## Plot the expected values with a window of width 5
exp.values <- roll.win(1:100, window = 5, indicator = "mean")
plot(exp.values)
## Spurious regression example
set.seed(123)
N <- 10^3
p.values <- rep(NA, N)
for (i in 1:N) {
x <- 1:100 + rnorm(100) # time series with trend
y <- 1:100 + rnorm(100) # time series with trend
p.values[i] <- summary(ols(y ~ x))$coef[2,4]
}
sum(p.values < 0.05)/N # share of significant results (100%)
for (i in 1:N) {
x <- rnorm(100) # time series without trend
y <- 1:100 + rnorm(100) # time series with trend
p.values[i] <- summary(ols(y ~ x))$coef[2,4]
}
sum(p.values < 0.05)/N # share of significant results (~ 5%)
Run the code above in your browser using DataLab