This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Class: LinearModel

Durbin-Watson test of linear model


P = dwtest(mdl)
[P,DW] = dwtest(mdl)
[P,DW] = dwtest(mdl,method)
[P,DW] = dwtest(mdl,method,tail)


P = dwtest(mdl) returns the p-value of the Durbin-Watson test on the mdl linear model.

[P,DW] = dwtest(mdl) also returns the Durbin-Watson statistic, DW.

[P,DW] = dwtest(mdl,method) specifies the method dwtest uses to compute the p-value.

[P,DW] = dwtest(mdl,method,tail) specifies the alternative hypothesis.

Input Arguments

expand all

Full, fitted linear regression model, specified as a LinearModel object constructed using fitlm or stepwiselm.

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 400, 'approximate' otherwise.

Alternative hypothesis to test, specified as one of the following:

TailAlternative Hypothesis

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 mdl has no serial correlation against the specified alternative hypotheses.

Output Arguments

expand all

p-value of the test, returned as a numeric value. 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 correlated.

Durbin-Watson statistic, returned as a numeric value.


expand all

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 =


There is significant autocorrelation in the residuals.


expand all


Approximate calculation of the p-value 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 Durbin-Watson Statistic. Applied Statistics 29, pp. 224–227, 1980.

Was this topic helpful?