Hi, I am so novice in using R. I have some problems in my R script below which fits time series data and predict it one-step ahead. Here is a brief explanation on what I try to achieve Th16k is time series data (500 data points). The size of window for fitting and predicting is 50 (data points). As you can easily discover from my code, (fixed) window is moving/sliding to get next one-step ahead prediction. The predicted value will be saved in pth. The problem is, every time I execute following script, I got error saying> source("C:\\R\\arima.R")Error in arima(temp, order = c(1, 0, 1)) : non-stationary AR part from CSS I think there should be better way to achieve this goal without using for loop. If you can share your knowledge, please advise me!!! :-) <----------------------------------------------------------------------- -----------------------------> w <- 50 pth <- th16k[1:w] limit <- length(th16k)-w for (i in 1:limit) { ws <- i we <- i+w-1 temp <- th16k[ws:we] fit <- arima(temp, order=c(1, 0, 1)) pred <- predict(fit, n.ahead=1) pth[i+w] <- pred$pred } plot(pth) <----------------------------------------------------------------------- -----------------------------> [[alternative HTML version deleted]]
Have you received a reply to this post? I have not seen one. If you would still like some suggestions from this group, please provide more detail on your question, as requested in the posting guide (www.R-project.org/posting-guide.html), including which version of R under which operating system. If I understand your post, you have two questions: (1) the error message and (2) the need for a loop. Regarding the error message, I can not replicate it. The message suggests a series that is nonstationary. However, I don't get that message from 'arima(1:50, order=c(1,0,1))', which is clearly nonstationary. What's in the file "C:\\R\\arima.R"? Can you replicate the error without using a "source" command? Regarding the need for a loop, I'm sorry, but I don't know enough about time series in R to answer your question. I'm currently studying Venables and Ripley (2002) Modern Applied Statistics with S, 4th ed. (Springer), ch. 14. If you are not familiar with this book, I highly recommend it. Ch. 14 is on time series. If you would like more comments on your question regarding a loop, I suggest you rephrase your question in terms of a standard example like "lh", fitting to, e.g., windows of length 30 in this series of 48 observations, explaining also very briefly what you are trying to accomplish with the loop. spencer graves park wrote:> Hi, > > I am so novice in using R. I have some problems in my R script below > which fits time series data and predict it one-step ahead. Here is a > brief explanation on what I try to achieve > > Th16k is time series data (500 data points). The size of window for > fitting and predicting is 50 (data points). As you can easily discover > from my code, (fixed) window is moving/sliding to get next one-step > ahead prediction. The predicted value will be saved in pth. > > The problem is, every time I execute following script, I got error > saying > > >>source("C:\\R\\arima.R") > > Error in arima(temp, order = c(1, 0, 1)) : > non-stationary AR part from CSS > > I think there should be better way to achieve this goal without using > for loop. If you can share your knowledge, please advise me!!! :-) > > <----------------------------------------------------------------------- > -----------------------------> > w <- 50 > pth <- th16k[1:w] > limit <- length(th16k)-w > for (i in 1:limit) { > ws <- i > we <- i+w-1 > temp <- th16k[ws:we] > fit <- arima(temp, order=c(1, 0, 1)) > pred <- predict(fit, n.ahead=1) > pth[i+w] <- pred$pred > } > plot(pth) > <----------------------------------------------------------------------- > -----------------------------> > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA spencer.graves at pdf.com www.pdf.com <http://www.pdf.com> Tel: 408-938-4420 Fax: 408-280-7915
Regarding the loop, the code below:> ws <- i > we <- i+w-1 > temp <- th16k[ws:we]can be written as: temp <- th16k[seq(i, length = w)] or you can get rid of the loop entirely using embed or using running in package gtools or rapply in the zoo package.> park wrote: > > Hi, > > > > I am so novice in using R. I have some problems in my R script below > > which fits time series data and predict it one-step ahead. Here is a > > brief explanation on what I try to achieve > > > > Th16k is time series data (500 data points). The size of window for > > fitting and predicting is 50 (data points). As you can easily discover > > from my code, (fixed) window is moving/sliding to get next one-step > > ahead prediction. The predicted value will be saved in pth. > > > > The problem is, every time I execute following script, I got error > > saying > > > > > >>source("C:\\R\\arima.R") > > > > Error in arima(temp, order = c(1, 0, 1)) : > > non-stationary AR part from CSS > > > > I think there should be better way to achieve this goal without using > > for loop. If you can share your knowledge, please advise me!!! :-) > > > > <----------------------------------------------------------------------- > > -----------------------------> > > w <- 50 > > pth <- th16k[1:w] > > limit <- length(th16k)-w > > for (i in 1:limit) { > > ws <- i > > we <- i+w-1 > > temp <- th16k[ws:we] > > fit <- arima(temp, order=c(1, 0, 1)) > > pred <- predict(fit, n.ahead=1) > > pth[i+w] <- pred$pred > > } > > plot(pth) > > <----------------------------------------------------------------------- > > -----------------------------> > > > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > -- > Spencer Graves, PhD > Senior Development Engineer > PDF Solutions, Inc. > 333 West San Carlos Street Suite 700 > San Jose, CA 95110, USA > > spencer.graves at pdf.com > www.pdf.com <http://www.pdf.com> > Tel: 408-938-4420 > Fax: 408-280-7915 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >