Here is the source code for the new function:
And here is an example, using a linear model with xregs:
I am particularly excited about this code because it will allow me to apply arbitrary machine learning algorithms to forecasting problems. For example, I could create an xreg matrix of lags and use a support vector machine, neural network, or random forest to make 1-step forecasts. I am planning to release this code as a package on CRAN, once I finish the documentation. I'm also planning to re-work the function a bit to return an S3 class, containing:
- Predicted values at each forecast horizon, including beyond the length of the input time series.
- Actual values at each forecast horizon, for easy comparison to #1.
- Matrix of average error at each horizon.
- The final model.
- Forecasts using the final model, from the last observation of x to the "max horizon".
- A print method that will show #3.
- A plot method that will plot #3.
Let me know if you have any suggestions or spot any bugs!