[R] Need help with for loop in forecast

tobiasfa tobias.farnlycke at gmail.com
Mon Nov 30 21:13:26 CET 2009


Hi

I have a ts from 1980:1 trough 2009:9 with a frequency of 12. I want to make
25 6 month forecast where the first 6 month forecast is between 2007:4 -
2007:9 and the last 2009:4 - 2009:9.

My script:

Forecast <- list()
for (i in 1:25){
j <- i + 326
Data <- window(omxr, end = time(omxr)[j])
Result <- ets(Data, model = "MAM")
Forecast[[i]] <- forecast(Result, 6)
}

#1. How can I be sure that i=1 -> all data prior to 2007:4, i=2 -> all data
prior to 2007:5, i=3 -> all data prior to 2007:6, ... 

#2. How do I only get the mean(point forecast) of every forecast? Now I get
"Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95"

#3. How can I put all 25 forecasts in a ts or matrix? I´ve tried the
following:
Forecast <- ts(matrix(NA, nrow = 6, ncol = 25))
Forecast <- ts(matrix(NA, nrow = 25, ncol = 6)) 
Forecast <- ts(matrix())
Forecast <- ts()
Forecast <- "just about everything"


Any help will be very appreciated!

Regards Tobias
-- 
View this message in context: http://n4.nabble.com/Need-help-with-for-loop-in-forecast-tp931580p931580.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list