p = dwtest(r,x) returns
the p-value for the Durbin-Watson test of the null hypothesis
that the residuals from a linear regression are uncorrelated. The
alternative hypothesis is that there is autocorrelation among the
residuals.

p = dwtest(r,x,Name,Value) returns
the p-value for the Durbin-Watson test with additional
options specified by one or more name-value pair arguments. For example,
you can conduct a one-sided test or calculate the p-value
using a normal approximation.

Create a design matrix using the census date (cdate)
as the predictor. Add a column of 1 values to include
a constant term.

n = length(cdate);
x = [ones(n,1),cdate];

Fit a linear regression to the data.

[b,bint,r] = regress(pop,x);

Test the null hypothesis that there is no autocorrelation
among regression residuals, against the alternative hypothesis that
the autocorrelation is greater than zero.

[p,dw] = dwtest(r,x,'Tail','right')

p =
0
dw =
0.1308

The returned value p = 0 indicates rejection
of the null hypothesis at the 5% significance level, in favor of the
alternative hypothesis that the autocorrelation among residuals is
greater than zero.

Regression residuals, specified as a vector. Obtain r by
performing a linear regression using a function such as regress, or by using the backslash operator.

Data Types: single | double

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments.
Name is the argument
name and Value is the corresponding
value. Name must appear
inside single quotes (' ').
You can specify several name and value pair
arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Tail','right','Method','approximate' specifies
a right-tailed hypothesis test and calculates the p-value using a
normal approximation.

p-value of the test, returned as a scalar
value in the range [0,1]. p is the probability
of observing a test statistic as extreme as, or more extreme than,
the observed value under the null hypothesis. Small values of p cast
doubt on the validity of the null hypothesis.

The Durbin-Watson test is used to test if linear
regression residuals are uncorrelated, against the alternative that
autocorrelation exists.

The test statistic is

where T is the
number of observations, and e_{t} is
the residual at time t.

The p-value can be calculated exactly using
the Pan algorithm. Alternatively, the p-value can
be estimated using a normal approximation. Significantly small p-values
indicate correlation among residuals.