# ?? list example
# Just a vector to be forecasted
n <- 100
D <- data.list()
D$t <- 1:n
D$y <- c(filter(rnorm(n), 0.95, "recursive"))
plot(D$y, type="l")
# Generate a forecast matrix with a simple persistence model
D$Yhat <- persistence(D$y, kseq=1:4)
# The residuals for each horizon
D$Resid <- residuals(D$Yhat, D$y)
D$Resid
# Note the names of the columns
names(D$Resid)
# which means that they are aligned with the observations and will not be lagged in the plot
plot_ts(D, c("y|Yhat","Resid"))
# Check that it matches (the forecasts is lagged in the plot_ts
# such that the forecast for t+k is at t+k (and not t))
plot_ts(D, c("y|Yhat","Resid"), xlim=c(1,10), kseq=1,
plotfun=function(x,...){lines(x,...,type="b")})
# Just for fun, see the auto-correlation function of the persistence
acf(D$Resid$h1, na.action=na.pass)
acf(D$Resid$h4, na.action=na.pass)
Run the code above in your browser using DataLab