I'm currently working with some time series data with the xts package, and would like to generate a forecast 12 periods into the future. There are limited observations, so I am unable to use an ARIMA model for the forecast. Here's the regression setup, after converting everything from zoo objects to vectors. hire.total.lag1 <- lag(hire.total, lag=-1, na.pad=TRUE) lm.model <- lm(hire.total ~ case.total + hire.total.lag1) hire.total is a monthly historical time series from Jan 2010 to Oct 2011. hire.total.lag1 is the same time series, lagged 1 period backwards. case.total is a monthly historical time series from Jan 2010 to Oct 2011, plus forecasts forward another 12 periods. I'd like to use this model to forecast hire.total for the next period, and use each successive prediction of hire.total as the lag1 "observation" for the next prediction. I have enough "observed" values for case.total to forecast out as far as I need. I might be able to construct this using a loop, but I have a feeling it will be messy and slow. Any suggestions? -- View this message in context: http://r.789695.n4.nabble.com/forecasting-linear-regression-from-lagged-variable-tp4125091p4125091.html Sent from the R help mailing list archive at Nabble.com.
forecasting linear regression from lagged variable
3 messages · AaronB, Mark Leeds, Gabor Grothendieck
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111130/6cbd226a/attachment.pl>
On Wed, Nov 30, 2011 at 4:40 PM, AaronB <aaron at communityattributes.com> wrote:
I'm currently working with some time series data with the xts package, and would like to generate a forecast 12 periods into the future. There are limited observations, so I am unable to use an ARIMA model for the forecast. Here's the regression setup, after converting everything from zoo objects to vectors. hire.total.lag1 <- lag(hire.total, lag=-1, na.pad=TRUE) lm.model <- lm(hire.total ~ case.total + hire.total.lag1) hire.total is a monthly historical time series from Jan 2010 to Oct 2011. hire.total.lag1 is the same time series, lagged 1 period backwards. case.total is a monthly historical time series from Jan 2010 to Oct 2011, plus forecasts forward another 12 periods. I'd like to use this model to forecast hire.total for the next period, and use each successive prediction of hire.total as the lag1 "observation" for the next prediction. I have enough "observed" values for case.total to forecast out as far as I need. I might be able to construct this using a loop, but I have a feeling it will be messy and slow. Any suggestions?
Its not clear that you can't use an arima model. You would use the n.ahead= argument of predict.Arima. The dyn and dynlm packages handle lagged lm's of zoo objects but you will have to do a predict and then append the prediction to the data and repeat in a loop as you describe. If you want to be careful about error terms then its more complex.
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com