使用arima来预测时间序列

时间:2017-08-03 11:09:42

标签: r prediction forecasting arima

我尝试使用ARIMA来预测时间序列。

ts <- c(283.678,278.158,273.345,269.773,265.863,265.673,262.977,272.557,267.628,270.106,276.346,292.736,310.649,320.550,332.954,350.313,361.524,367.406,369.442,372.043,365.030,375.210,371.006,364.991,359.975,365.849,373.687,368.167,368.281,366.982,365.752,366.844,356.526,356.667,354.937,352.461,353.742,357.139,362.981,384.613,405.519,400.974,388.696,374.536,348.781,324.664,307.051,297.943)
ar <- arima(ts)
ps <- predict(ar, 48)
plot(c(ts, ps$pred), type="l")

为什么这段代码会预测普通线而不是一些类似的曲线?

enter image description here

1 个答案:

答案 0 :(得分:0)

因为您忘记在order中添加变量arima(),因此符合ARIMA(0,0,0)模型,这只是一个常数拦截项。

如果您想自动适合适当顺序的ARIMA模型(由AIC,AICc或BIC选择),您可以使用auto.arima()包中的forecast

library(forecast)
ar <- auto.arima(ts)
ps <- predict(ar, 10)
ps
# $pred
# Time Series:
# Start = 49 
# End = 58 
# Frequency = 1 
# [1] 291.7978 287.6517 284.8543 282.9668 281.6934 280.8342 280.2545 279.8634 279.5995 279.4214