The Durbin-Watson test assesses whether there is autocorrelation among the residuals or not.
The Durbin-Watson test statistic,
where ri is the ith raw residual, and n is the number of observations.
After obtaining a fitted model, say,
stepwiselm, you can perform the Durbin-Watson test
dwtestmethod of the
This example shows how to test for autocorrelation among the residuals of a linear regression model.
Load the sample data and fit a linear regression model.
load hald mdl = fitlm(ingredients,heat);
Perform a two-sided Durbin-Watson test to determine if there is any autocorrelation among the residuals of the linear model,
[p,DW] = dwtest(mdl,'exact','both')
p = 0.8421
DW = 2.0526
The value of the Durbin-Watson test statistic is 2.0526. The -value of 0.8421 suggests that the residuals are not autocorrelated.