| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Statistics Toolbox |
| Contents | Index |
| Learn more about Statistics Toolbox |
[P,DW] = dwtest(R,X)
[...] = dwtest(R,X,method)
[...] = dwtest(R,X,method,tail)
[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:
'exact' — Calculates an exact p-value using the PAN algorithm (the default if the sample size is less than 400).
'approximate' — Calculates the p-value using a normal approximation (the default if the sample size is 400 or larger).
[...] = dwtest(R,X,method,tail) performs the test against one of the following alternative hypotheses, specified by tail:
| Tail | Alternative 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). |
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')
![]() | dummyvar | ecdf | ![]() |

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 |