Извлечь прогнозные значения из временных рядов ARIMA в R - PullRequest
0 голосов
/ 14 января 2020

Итак, я сделал прогноз по временным рядам с использованием ARIMA, но так же, как и график прогноза (который у меня уже есть), я хотел бы получить прогнозные значения (таблица или кадр данных). Я довольно новичок в использовании временных рядов, и я попытался использовать fit () из библиотеки 'Forecast', и это не сработало:

auto.arima(data_1, ic = 'aic', trace = TRUE)
arima_1 <- auto.arima(data_1)
#forecast for the next #2 years:
arima_forecast <- forecast(arima_1, level=c(95), h=2*12)
plot(arima_forecast)
#to get the prediction as values instead of plot:
fit_arima <- arima(arima_1, order = c(0,1,3), seasonal = c(0,1,3))
fitted(fit_arima)

#The code above returns the values of the original time series and NOT the #forcasted ones (2017 and 2018), and it also comes with with an error:

           Jan       Feb       Mar       Apr       May       Jun       Jul       Aug       Sep       Oct       Nov       Dec
2009  395.6040  405.2486  490.6325  566.9798  469.3448  562.8849  541.1502  724.9255  598.0615  652.7285  606.9284  585.4416
2010  578.1152  717.6219 1024.7447  722.8073  852.1060  706.8463  993.0397 1098.8557 1173.3702  998.8207 1053.5713  958.7022
2011  917.3844 1054.5153  808.1892 2232.2261 1823.5009 2287.3903 4965.0257 5708.6537 3012.0549 1685.6048 2335.0936 1961.5053
2012 1929.2727 2007.1000 2638.8384 8874.8829 8493.8622 9067.2932 4911.2495 5327.2379 6840.4109 5097.0099 6380.2266 6610.2231
2013 3505.3007 6339.6027 6947.4970 7058.4215 4943.8889 4136.6280 5698.1434 5514.1045 3972.1105 4183.3841 6409.3745 3044.1092
2014 3850.7902 4303.9861 3795.8950 2844.2147 3776.8973 3467.1902 3692.4136 5572.5246 3902.4891 5793.0275 5413.1510 3939.6510
2015 3703.3364 4005.8152 3823.2318 4107.2428 3635.8163 3510.2180 4882.3563 5465.2936 4407.9635 5224.8112 5715.1888 3460.4828
2016 3286.1393 4460.5952 3602.2906 3439.9445 3533.6158 3452.3477 4598.0682 4836.6610 4392.4629 4855.7589 4440.1916 3687.8484
> fit_arima <- arima(arima_1, order = c(0,1,3), seasonal = c(0,1,3))
Error in arima(arima_1, order = c(0, 1, 3), seasonal = c(0, 1, 3)) : 
  'x' must be numeric

# I also tried using data_1 instead of arima_1, but I get the same thing:

> fit_arima <- arima(data_1, order = c(0,1,3), seasonal = c(0,1,3))
> fitted(fit_arima)

           Jan       Feb       Mar       Apr       May       Jun       Jul       Aug       Sep       Oct       Nov       Dec
2009  395.7714  476.8350  592.7940  505.9231  575.8754  548.9211  770.7258  661.8626  698.8429  629.9243  621.9388  588.3085
2010  717.7772  884.4448 1112.1270  765.0612  910.6655  790.9241 1204.4750 1151.5348 1250.7689 1034.1927 1082.6245  952.6650
2011  989.6472 1147.1997 1084.4455 2357.5909 2056.2874 2964.2982 5720.2411 5729.9657 2846.8788 1687.9639 2266.9019 1951.6146
2012 2034.1357 2114.2238 3854.1433 9557.3790 9279.0610 9381.5013 5538.8673 5374.4981 6739.6057 5324.9155 6396.3091 6474.5565
2013 3869.9783 6334.1700 8099.2994 6971.2730 5273.1076 4456.4170 6302.8866 5323.8125 3452.4915 4511.4452 6117.6934 2636.9520
2014 4096.4115 4174.4574 5006.1436 2956.1161 4220.4652 3628.6219 4409.8066 5561.7219 3577.4032 6237.6835 5205.3413 3349.8508
2015 4107.7087 3778.1410 5168.9899 4096.5479 4038.5343 3641.6978 5556.5244 5352.0569 4014.3955 5817.7059 5298.9343 2805.7216
2016 3709.6293 4114.3894 4716.9123 3340.7973 3858.3439 3581.6665 5309.0177 4668.4745 4124.8470 5449.4714 3943.7697 3074.2260

Приведенный выше код приносит только значения временных рядов, но НЕ прогнозируемые / прогнозируемые значения, кто-нибудь может помочь? :)

...