P = dwtest(mdl)
[P,DW] = dwtest(mdl)
[P,DW] = dwtest(mdl,method)
[P,DW] = dwtest(mdl,method,tail)
mdl— Full, fitted linear regression model
method— Algorithm for computing p-value
Algorithm for computing the p-value, specified as one of the following:
'exact' — Calculates an
exact p-value using Pan's algorithm.
'approximate' — Calculates
the p-value using a normal approximation.
The default is
'exact' when the sample size
is less than
tail— Alternative hypothesis to test
Alternative hypothesis to test, specified as one of the following:
Serial correlation is not 0.
Serial correlation is greater than 0 (right-tailed test).
Serial correlation is less than 0 (left-tailed test).
dwtest tests whether
no serial correlation against the specified alternative hypotheses.
P— p-value of the testnumeric value
p-value of the test, returned as a numeric
dwtest tests if the residuals are uncorrelated,
against the alternative that there is autocorrelation among them.
Small values of
P indicate that the residuals are
DW— Durbin-Watson statisticnumeric value
Durbin-Watson statistic, returned as a numeric value.
Let r be the vector of residuals (in
The Durbin-Watson statistic is
Examine whether the residuals from a fitted model of census data over time have autocorrelated residuals.
Load the census data and create a linear model.
load census mdl = fitlm(cdate,pop);
Find the -value of the Durbin-Watson autocorrelation test.
P = dwtest(mdl)
P = 0
There is significant autocorrelation in the residuals.
 Durbin, J., and G. S. Watson. Testing for Serial Correlation in Least Squares Regression I. Biometrika 37, pp. 409–428, 1950.
 Farebrother, R. W. Pan's Procedure for the Tail Probabilities of the Durbin-Watson Statistic. Applied Statistics 29, pp. 224–227, 1980.