On Wed, Nov 30, 2011 at 4:40 PM, AaronB <aa...@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 ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.