📦 10,000 random walks, three DF regressions each
df_stats <- function(x, det) { # returns T(rho_hat - 1) and tau
y <- x[-1]; xl <- x[-length(x)]; n <- length(y)
X <- switch(det, none = cbind(xl), const = cbind(1, xl),
trend = cbind(1, seq_len(n), xl))
fit <- .lm.fit(X, y); k <- ncol(X); b <- fit$coefficients[k]
se <- sqrt(sum(fit$residuals^2) / (n - k) * solve(crossprod(X))[k, k])
c(n * (b - 1), (b - 1) / se)
}
T <- 500; R <- 10000
sims <- t(replicate(R, { x <- cumsum(rnorm(T))
c(df_stats(x, "none"), df_stats(x, "const"), df_stats(x, "trend")) }))
colnames(sims) <- c("rho_none", "tau_none", "rho_const", "tau_const",
"rho_trend", "tau_trend")
round(apply(sims, 2, quantile, c(0.01, 0.05, 0.10)), 2)
mean(sims[, "rho_none"] < 0) # theory: P(chi2(1) < 1) = 0.683 rho_none tau_none rho_const tau_const rho_trend tau_trend
1% -14.07 -2.63 -20.10 -3.42 -27.88 -3.96
5% -7.86 -1.93 -13.88 -2.87 -21.47 -3.42
10% -5.57 -1.60 -11.21 -2.59 -17.96 -3.13
[1] 0.6834


