P = dwtest(mdl)
[P,DW] =
dwtest(mdl)
[P,DW] =
dwtest(mdl,method)
[P,DW] =
dwtest(mdl,method,tail)
returns
the pvalue of the DurbinWatson test on the P
= dwtest(mdl
)mdl
linear
model.
[
returns the DurbinWatson
statistic.P
,DW
] =
dwtest(mdl
)
[
specifies
the method P
,DW
] =
dwtest(mdl
,method
)dwtest
uses to compute the pvalue.
[
specifies
the alternative hypothesis.P
,DW
] =
dwtest(mdl
,method
,tail
)

Linear model, as constructed by  

Algorithm for computing the pvalue:
Default:  

Default: 

pvalue of the test, a scalar. 

Value of the DurbinWatson statistic, a scalar. 
Let r be the vector of residuals (in mdl.residuals.response
).
The DurbinWatson statistic is
$$DW=\frac{{\displaystyle \sum _{i=1}^{n1}{\left({r}_{i+1}{r}_{i}\right)}^{2}}}{{\displaystyle \sum _{i=1}^{n}{r}_{i}^{2}}}.$$
Approximate calculation of the pvalue uses a normal approximation [1]. Exact calculation uses Pan's algorithm [2].
[1] Durbin, J., and G. S. Watson. Testing for Serial Correlation in Least Squares Regression I. Biometrika 37, pp. 409–428, 1950.
[2] Farebrother, R. W. Pan's Procedure for the Tail Probabilities of the DurbinWatson Statistic. Applied Statistics 29, pp. 224–227, 1980.