将双差和预测预测转换为R中的实际值

时间:2019-04-22 00:56:48

标签: r time-series arima forecast

我实际上正在学习R上的时间序列,但是我无法将预测值转换为实际值。我为我的英语道歉,我不是本地人。我在解释自己:

这些是我的价值观:

> nbats
     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2004  20  22  18  23  25  27  15  12  11  17  26  22
2005  21  25  21  25  26  29  14  12  11  17  22  22
2006  21  25  20  22  28  27  14  10  11  15  21  24
2007  22  24  20  26  29  24  14  11  10  15  23  22
2008  21  27  27  29  35  30  14  12  11  18  25  26
2009  24  28  24  29  38  29  15  11  11  18  23  24
2010  23  26  20  26  31  33  20  13  12  22  24  26
2011  25  32  26  35  42  36  11   8   8  11  12  27
2012  30  38  33  33  44  49  21  14  11  19  28  29
2013  30  34  32  36  42  51  19  11  10  19  28  29
2014  29  31  27  38  47  38  20  12  10  21  30  33
2015  30  31  27  40  47  50  17  10  11  19  33  37
2016  39  41  38  53  70  73  24  12  14  25  43  71
2017  44  48  44  68  65  69  25  15  17  39  50  51
2018  52  54  50  81 100  58  25  14  15  41  58  60

https://image.noelshack.com/fichiers/2019/17/1/1555894195-rplot01.jpeg

首先,我将数据分为两部分,以将预测值与实际值进行比较。

donnees_app = ts(donnees[1:(length(donnees)-6)],start=2004,frequency=12)
donnees_valid = ts(donnees[-(1:(length(donnees)-6))],start=c(2018,7),frequency = 12)

我的数据不是平稳的,所以我只对数据应用对数函数以对方差进行归类,然后两次相差以均值进行归类。

nba.statioVar=log(donnees_app)
nba.statioMoy=diff(nba.statioVar,lag=1)
nba.statioMoy2=diff(nba.statioVar,differences=2)
> nba.statioMoy2
               Jan           Feb           Mar           Apr           May           Jun           Jul           Aug
2004                             -0.2959808753  0.4457931535 -0.1617408491 -0.0064205678 -0.6647477060  0.3646431136
2005  0.1205340690  0.2208734028 -0.3487067743  0.3487067743 -0.1351326740  0.0699785788 -0.8374377923  0.5740878205
2006 -0.0465200156  0.2208734028 -0.3974969385  0.3184537311  0.1458518770 -0.2775297010 -0.6204118922  0.3203072998
2007 -0.2205427696  0.1740227540 -0.2693329338  0.4446858213 -0.1531649725 -0.2984412916 -0.3497545011  0.2978344439
2008 -0.0020682531  0.2978344439 -0.2513144283  0.0714589640  0.1165932675 -0.3422029113 -0.6079893722  0.6079893722
2009 -0.1192634208  0.2341933875 -0.3083013597  0.3433926795  0.0810483301 -0.5405806595 -0.3889552991  0.3490907006
2010 -0.0851192288  0.1651619365 -0.3849665866  0.5247285289 -0.0864735980 -0.1133703095 -0.5632956449  0.0699923718
2011 -0.1192634208  0.2860807911 -0.4544994427  0.5048908882 -0.1149299667 -0.3364722366 -1.0314729858  0.8671699345
2012 -0.7055697006  0.1310282624 -0.3774673763  0.1410785983  0.2876820725 -0.1800514083 -0.9549285246  0.4418327523
2013 -0.0011897681  0.0912615913 -0.1857877648  0.1784076575  0.0363676442  0.0400053346 -1.1815426680  0.4408429472
2014 -0.0350913198  0.0666913745 -0.2048417130  0.4798996322 -0.1291878517 -0.4251228840 -0.4292924442  0.1310282624
2015 -0.1906203596  0.1281000026 -0.1709401613  0.5311929266 -0.2317744405 -0.0993927439 -1.1406850651  0.5481814103
2016 -0.0617666177 -0.0026333129 -0.1259963276  0.4086916608 -0.0545024253 -0.2362391294 -1.1543698099  0.4192584302
2017 -0.9799700045  0.5655016201 -0.1740227540  0.5223294482 -0.4804385065  0.1048396700 -1.0749499144  0.5044050560
2018 -0.0003845414  0.0183222421 -0.1147013691  0.5593871904 -0.2717051179 -0.7554482068                            
               Sep           Oct           Nov           Dec
2004  0.1361321743  0.5223294482 -0.0104348773 -0.5919372786
2005  0.0671393028  0.5223294482 -0.1774889620 -0.2578291093
2006  0.4317824164  0.2148447485  0.0263173083 -0.2029408440
2007  0.1458518770  0.5007752879  0.0219789067 -0.4718957774
2008  0.0671393028  0.5794878621 -0.1639724181 -0.2892833538
2009  0.3101549283  0.4924764851 -0.2473540271 -0.2025628436
2010  0.3507402084  0.6861785112 -0.5191244266 -0.0069686693
2011  0.3184537311  0.3184537311 -0.2314423541  0.7239188392
2012  0.1643030513  0.7877057632 -0.1587781754 -0.3526742112
2013  0.4512335266  0.7371640660 -0.2540883552 -0.3526742112
2014  0.3285040670  0.9242589015 -0.3852624008 -0.2613647641
2015  0.6259384309  0.4512335266  0.0055248759 -0.4376582311
2016  0.8472978604  0.4256678154 -0.0374942044 -0.0408445295
2017  0.6359887667  0.7051851591 -0.5818869428 -0.2286587320
2018                              

我使用auto.arima函数确定ARIMA模型,并保留ARIMA(3,0,3)。

所以我做了6个月的预测:

prev5 = forecast(mod5,h=6) #mod5 is the ARIMA(3,0,3) model

https://image.noelshack.com/fichiers/2019/17/1/1555894041-rplot.jpeg

我希望在与第一个相同的图形中显示预测(在y轴上,值从20到100,而不是-1到1)

我不知道我是否很清楚,但我希望你能帮助我。

谢谢!

0 个答案:

没有答案