DurbinWatsonTest(formula, order.by = NULL,
alternative = c("greater", "two.sided", "less"),
iterations = 15, exact = NULL, tol = 1e-10, data = list())
"lm"
object).z
or a formula with a single explanatory
variable like ~ z
. The observations in the model
are ordered by the size of z
. If set to NULL
(the
default) the observations are asFALSE
a normal approximation
will be used to compute the p value, if TRUE
the "pan"
algorithm is used. The default is to use "pan" if the sample size
is < 100.tol
to be treated as non-zero.DurbinWatsonTest
is called from."htest"
containing:alternative
argument.
Under the assumption of normally distributed disturbances, the null distribution
of the Durbin-Watson statistic is the distribution of a linear
combination of chi-squared variables. The p-value is computed using the
Fortran version of Applied Statistics Algorithm AS 153 by Farebrother
(1980, 1984). This algorithm is called "pan" or "gradsol". For large sample
sizes the algorithm might fail to compute the p value; in that case a warning
is printed and an approximate p value will be given; this p value is computed
using a normal approximation with mean and variance of the Durbin-Watson test
statistic.
Examples can not only be found on this page, but also on the help pages of the
data sets bondyield
, currencysubstitution
,
growthofmoney
, moneydemand
,
unemployment
, wages
.
For an overview on R and econometrics see Racine & Hyndman (2002).lm
## generate two AR(1) error terms with parameter
## rho = 0 (white noise) and rho = 0.9 respectively
err1 <- rnorm(100)
## generate regressor and dependent variable
x <- rep(c(-1,1), 50)
y1 <- 1 + x + err1
## perform Durbin-Watson test
DurbinWatsonTest(y1 ~ x)
err2 <- filter(err1, 0.9, method="recursive")
y2 <- 1 + x + err2
DurbinWatsonTest(y2 ~ x)
Run the code above in your browser using DataCamp Workspace