Products & Services Industries Academia Support User Community Company

Learn more about Statistics Toolbox   

dwtest - Durbin-Watson test

Syntax

[P,DW] = dwtest(R,X)
[...] = dwtest(R,X,method)
[...] = dwtest(R,X,method,tail)

Description

[P,DW] = dwtest(R,X) performs a Durbin-Watson test on the vector R of residuals from a linear regression, where X is the design matrix from that linear regression. P is the computed p-value for the test, and DW is the Durbin-Watson statistic. The Durbin-Watson test is used to test if the residuals are uncorrelated, against the alternative that there is autocorrelation among them.

[...] = dwtest(R,X,method) specifies the method to be used in computing the p-value. method can be either of the following:

[...] = dwtest(R,X,method,tail) performs the test against one of the following alternative hypotheses, specified by tail:

TailAlternative Hypothesis
'both'

Serial correlation is not 0.

'right'

Serial correlation is greater than 0 (right-tailed test).

'left'

Serial correlation is less than 0 (left-tailed test).

Examples

Fit a straight line to the census data and note the autocorrelation in the residuals:

load census
n = length(cdate);
X = [ones(n,1),cdate];
[b,bint,r1] = regress(pop,X);
p1 = dwtest(r1,X)
plot(cdate,r1,'b-',cdate,zeros(n,1),'k:')

Adding a squared term reduces the autocorrelation but it is still significantly different from zero:

X = [ones(n,1),cdate,cdate.^2];
[b,bint,r2] = regress(pop,X);
p2 = dwtest(r2,X)
line(cdate,r2,'color','r')

See Also

regress

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS