简体   繁体   中英

Forecasting time series with R forecast package

I'm relatively new to R programming, but I've been reading your blogs and posts in order to get up-to-date with the forecast package. However, I have been struggling with the effect of seasonality.

Take for example the simplest signal possible:

train <- ts(sin((2*pi)*seq(from=0, to=10, by=0.01)))

If I just try to forecast this signal with brute force, I get irrelevant results:

plot(forecast(train,h=20))

However, if I manually detect the seasonality as 100, and do the following:

train <- ts(sin((2*pi)*seq(from=0, to=10, by=0.01)),frequency=100)
plot(forecast(train))

I get excellent forecasting results.

I'm honestly very puzzled by these results, which obviously happen for more complex signals.

If I remember correctly, when you create the time series object you have to specify its frequency. That way, the forecast method will be able to detect the seasonal pattern. There are some other ways to detect seasonality, like trying the auto arima function and checking if it selects a seasonal model. Apart from visual exploration, of course.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM