Main Content

dwtest

Durbin-Watson test with linear regression model object

Description

p = dwtest(mdl) returns the p-value of the Durbin-Watson Test on the residuals of the linear regression model mdl. The null hypothesis is that the residuals are uncorrelated, and the alternative hypothesis is that the residuals are autocorrelated.

example

p = dwtest(mdl,method) specifies the algorithm for computing the p-value.

p = dwtest(mdl,method,tail) specifies the alternative hypothesis.

[p,DW] = dwtest(___) also returns the Durbin-Watson statistic using any of the input argument combinations in the previous syntaxes.

Examples

collapse all

Determine whether a fitted linear regression model has autocorrelated residuals.

Load the census data set and create a linear regression model.

load census
mdl = fitlm(cdate,pop);

Find the p-value of the Durbin-Watson autocorrelation test.

p = dwtest(mdl)
p = 
3.6190e-15

The small p-value indicates that the residuals are autocorrelated.

Input Arguments

collapse all

Linear regression model, specified as a LinearModel object created using fitlm or stepwiselm.

Algorithm for computing the p-value, specified as one of these values:

  • 'exact' — Calculate an exact p-value using Pan’s algorithm [2].

  • 'approximate' — Calculate the p-value using a normal approximation [1].

The default is 'exact' when the sample size is less than 400, and 'approximate' otherwise.

Type of alternative hypothesis to test, specified as one of these values:

ValueAlternative 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).

dwtest tests whether mdl has no serial correlation, against the specified alternative hypothesis.

Output Arguments

collapse all

p-value of the test, returned as a numeric value. dwtest tests whether the residuals are uncorrelated, against the alternative that autocorrelation exists among the residuals. A small p-value indicates that the residuals are autocorrelated.

Durbin-Watson statistic value, returned as a nonnegative numeric value.

More About

collapse all

Durbin-Watson Test

The Durbin-Watson test tests the null hypothesis that linear regression residuals of time series data are uncorrelated, against the alternative hypothesis that autocorrelation exists.

The test statistic for the Durbin-Watson test is

DW=i=1n1(ri+1ri)2i=1nri2,

where ri is the ith raw residual, and n is the number of observations.

The p-value of the Durbin-Watson test is the probability of observing a test statistic as extreme as, or more extreme than, the observed value under the null hypothesis. A significantly small p-value casts doubt on the validity of the null hypothesis and indicates autocorrelation among residuals.

References

[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.

Extended Capabilities

Version History

Introduced in R2012a