#Fit an AR(2) model to each rolling origin subset
far2 <- function(x, h){forecast(Arima(x, order=c(2,0,0)), h=h)}
e <- tsCV(lynx, far2, h=1)
#Fit the same model with a rolling window of length 30
e <- tsCV(lynx, far2, h=1, window=30)
#Example with exogenous predictors
far2_xreg <- function(x, h, xreg, newxreg) {
forecast(Arima(x, order=c(2,0,0), xreg=xreg), xreg=newxreg)
}
y <- ts(rnorm(50))
xreg <- matrix(rnorm(100),ncol=2)
e <- tsCV(y, far2_xreg, h=3, xreg=xreg)
Run the code above in your browser using DataLab