Tests first-order autocorrelation in temporally-ordered residuals.
Usage
durbin_watson(
object,
alternative = c("two.sided", "greater", "less"),
time = NULL,
resid_type = "pearson"
)Arguments
- object
A fitted model, or a numeric vector of temporally-ordered residuals. A fit's residuals are in its data's row order, so pass
timeunless the rows already are in time order.- alternative
"two.sided","greater"(positive autocorr), or"less"- time
Optional time index, one per residual; the residuals are put in increasing
timeorder before the statistic is formed.NULL(default) takes them in the order given.- resid_type
Residual type if extracting from a model (default
"pearson"), as formoran_i().
Examples
set.seed(1)
e <- as.numeric(arima.sim(list(ar = 0.6), n = 100))
durbin_watson(e)
# Residuals recorded out of time order:
tt <- sample(100)
durbin_watson(e[tt], time = tt)