bdNumeric
, or an object that inherits from class
"lm"
or class
bdLm
. If one of the latter two, the residuals are extracted from the object using the
residuals
function.
durbinWatson(x)
bdNumeric
or an object that inherits from class
"lm"
or
"bdLm"
.
"durbinWatson"
with the following components:
x
.
The default method for this function operates on a numeric vector. The method for class
"lm"
extracts the residuals from the object
x
using the
residuals
function, and then calls the default method on those residuals.
Currently, the only method for objects of class
"durbinWatson"
is
print
.
The Durbin-Watson statistic tests for first-order autocorrelation in least squares regression residuals.
It is defined as
sum((diff(x))^2)/var(x, SumSquares=T)
.
The statistic is bounded between 0 and 4; small values indicate possible positive autocorrelation and large values indicate possible negative autocorrelation.
For completely independent residuals, the statistic is symmetric around 2.
If the test is significant, the observations in your data set may not be independent and you should check the validity of your model assumptions.
The null distribution for the Durbin-Watson test statistic depends on the data matrix used to compute the linear model. Thus, significance tables are not built into S-PLUS. Instead, you can obtain approximate bounds for significance levels using the tables found in Durbin and Watson (1950); these tables are also available in many general statistics texts.
Durbin, J. and Watson, G.S. (1950). Testing for serial correlation in least squares regression I. Biometrika 37: 409-428.
cornreg <- lm(corn.yield ~ corn.rain) durbinWatson(cornreg)