Dear forum, I would like to forecast e.g. with the arima-model. To figure out which model works best I am going to predict with this models. my first code: for(ar.ord in 1:3){ for(ma.ord in 1:3){ print(predict(arima(para_qtr[1:(n-8),1],order=c(ar.ord,1,ma.ord)), n.ahead=8)$pred) } } this one works. but I want to "save" my results in a matrix or a data.frame. my second code: foreL<-8 b0f<-matrix(nrow=9, ncol=foreL) for(i in 1:9){ for(ar.ord in 1:3){ for(ma.ord in 1:3){ b0f[i,]<-c(predict(arima(para_qtr[1:(n-8),1],order=c(ar.ord,1,ma.ord)), n.ahead=foreL)$pred) } } } sure- this one doesn't work. the matrix b0f only consists of the forecast of the ARIMA(3,1,3)-model. I need the forecasts of ARIMA(1,1,1), ARIMA(2,1,1) ARIMA(3,1,1), ARIMA(3,1,2) and so on ad nauseam in the lines of the b0f matrix. I would be glad if someone could help me. best regards, fred -- View this message in context: http://r.789695.n4.nabble.com/Loops-tp3814162p3814162.html Sent from the R help mailing list archive at Nabble.com.
A little bit change of your code may do the work foreL<-8 b0f<-matrix(nrow=9, ncol=foreL) ct<-1 ### use this as the index of b0f for(ar.ord in 1:3){ for(ma.ord in 1:3){ b0f[ct,]<-c(predict(arima(para_qtr[1:(n-8),1],order=c(ar.ord,1,ma.ord)), n.ahead=foreL)$pred) ct<-ct+1 ### increment the counter } } Weidong Gu On Wed, Sep 14, 2011 at 5:36 PM, Fred <christoph_wegener at gmx.de> wrote:> Dear forum, > > I would like to forecast e.g. with the arima-model. To figure out which > model works best I am going to predict with this models. > > my first code: > > for(ar.ord in 1:3){ > for(ma.ord in 1:3){ > print(predict(arima(para_qtr[1:(n-8),1],order=c(ar.ord,1,ma.ord)), > n.ahead=8)$pred) > } > } > > this one works. but I want to "save" my results in a matrix or a data.frame. > > my second code: > foreL<-8 > b0f<-matrix(nrow=9, ncol=foreL) > for(i in 1:9){ > for(ar.ord in 1:3){ > for(ma.ord in 1:3){ > b0f[i,]<-c(predict(arima(para_qtr[1:(n-8),1],order=c(ar.ord,1,ma.ord)), > n.ahead=foreL)$pred) > } > } > } > sure- this one doesn't work. the matrix b0f only consists of the forecast of > the ARIMA(3,1,3)-model. I need the forecasts of ARIMA(1,1,1), ARIMA(2,1,1) > ARIMA(3,1,1), ARIMA(3,1,2) and so on ad nauseam in the lines of the b0f > matrix. > > I would be glad if someone could help me. > > best regards, fred > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Loops-tp3814162p3814162.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >
Look at the combinations function in gtools and index by the rows of that output for a single loop. Pass values as the three parameters. Sorry for being terse - writing on my phone. Michael On Sep 14, 2011, at 5:36 PM, Fred <christoph_wegener at gmx.de> wrote:> Dear forum, > > I would like to forecast e.g. with the arima-model. To figure out which > model works best I am going to predict with this models. > > my first code: > > for(ar.ord in 1:3){ > for(ma.ord in 1:3){ > print(predict(arima(para_qtr[1:(n-8),1],order=c(ar.ord,1,ma.ord)), > n.ahead=8)$pred) > } > } > > this one works. but I want to "save" my results in a matrix or a data.frame. > > my second code: > foreL<-8 > b0f<-matrix(nrow=9, ncol=foreL) > for(i in 1:9){ > for(ar.ord in 1:3){ > for(ma.ord in 1:3){ > b0f[i,]<-c(predict(arima(para_qtr[1:(n-8),1],order=c(ar.ord,1,ma.ord)), > n.ahead=foreL)$pred) > } > } > } > sure- this one doesn't work. the matrix b0f only consists of the forecast of > the ARIMA(3,1,3)-model. I need the forecasts of ARIMA(1,1,1), ARIMA(2,1,1) > ARIMA(3,1,1), ARIMA(3,1,2) and so on ad nauseam in the lines of the b0f > matrix. > > I would be glad if someone could help me. > > best regards, fred > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Loops-tp3814162p3814162.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
Thank you so much! foreL<-8 b0f<-matrix(nrow=9, ncol=foreL) ct<-1 ### use this as the index of b0f for(ar.ord in 1:3){ for(ma.ord in 1:3){ b0f[ct,]<-c(predict(arima(para_qtr[1:(n-8),1],order=c(ar.ord,1,ma.ord)), n.ahead=foreL)$pred) ct<-ct+1 ### increment the counter } } this one works! Best regards! -- View this message in context: http://r.789695.n4.nabble.com/Loops-tp3814162p3814971.html Sent from the R help mailing list archive at Nabble.com.
Maybe Matching Threads
- Generating list of vector coordinates
- Rsync with non-english characters in filenames?
- [LLVMdev] "Cannot select" error in 2.9
- [LLVMdev] Promoting i1 to i32 does not work...
- [LLVMdev] Help!!!!Help!!!! " LLVM ERROR: Cannot select: 0x9fc9680: i32 = fp32_to_fp16 0x9fc0750 [ID=16] " problem!!!!!!!!!!!!!!!!!!