错误:对于使用tbats的每周时间序列预测,highchart不会绘制

时间:2017-04-21 05:23:43

标签: r highcharts time-series forecasting

x = apply.monthly(xts(data1$Sales,order.by = date1),FUN = sum)
x = as.data.frame(x)
x1 = ts(x,frequency = 12,start = c(2011,1),end = c(2014,12))
hchart(forecast(auto.arima(x1)))

因此,预测输出为:

       Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
Jan 2015       358371.9 315315.3 401428.5 292522.5 424221.3
Feb 2015       323524.1 276176.7 370871.6 251112.4 395935.8
Mar 2015       381082.9 329802.3 432363.4 302656.1 459509.7
Apr 2015       362998.6 308065.9 417931.3 278986.3 447011.0
May 2015       415109.8 356753.0 473466.6 325860.8 504358.8
Jun 2015       509654.5 448063.7 571245.3 415459.5 603849.5
Jul 2015       377217.7 312554.5 441881.0 278323.9 476111.6
Aug 2015       517245.5 449649.3 584841.6 413866.0 620624.9
Sep 2015       552086.9 481679.9 622494.0 444408.6 659765.2
Oct 2015       485304.4 412194.4 558414.3 373492.4 597116.4
Nov 2015       583234.5 507518.1 658950.9 467436.3 699032.8
Dec 2015       586645.4 508409.3 664881.5 466993.6 706297.1
Jan 2016       424985.8 340008.8 509962.7 295024.7 554946.8
Feb 2016       390138.0 301632.4 478643.7 254780.3 525495.7
Mar 2016       447696.7 355797.8 539595.7 307149.4 588244.0
Apr 2016       429612.5 334441.2 524783.8 284060.5 575164.5
May 2016       481723.7 383388.8 580058.6 331333.5 632113.9
Jun 2016       576268.4 474868.6 677668.2 421190.8 731346.0
Jul 2016       443831.6 339456.9 548206.3 284204.3 603459.0
Aug 2016       583859.3 476592.2 691126.5 419808.3 747910.3
Sep 2016       618700.8 508617.1 728784.5 450342.4 787059.3
Oct 2016       551918.3 439088.4 664748.1 379359.8 724476.7
Nov 2016       649848.4 534337.6 765359.2 473189.9 826507.0
Dec 2016       653259.3 535128.3 771390.2 472593.6 833924.9

因此,对于上面的数据,highchart工作正常,但是当我尝试使用TBATS函数的每周数据时,它会给出类似下面的内容,

x1 = ts(x,freq = 365.25/7,start = 2011+31/365.25)
bestfit <- list(aicc=Inf)
fitmodel <- tbats(x1)
forecastweekly <- forecast(fitmodel, h=200)

并预测输出为:

         Point Forecast     Lo 80     Hi 80    Lo 95     Hi 95
2015.110       77239.91  62831.38  91648.44 55203.96  99275.86
2015.129       71852.27  57413.72  86290.82 49770.41  93934.13
2015.148       71560.14  57042.50  86077.79 49357.32  93762.96
2015.167       73289.48  58602.92  87976.04 50828.33  95750.64
2015.186       73652.31  58732.79  88571.84 50834.87  96469.76
2015.205       71700.22  56559.47  86840.98 48544.43  94856.02
2015.225       69387.13  54075.57  84698.69 45970.11  92804.14
2015.244       69554.04  54104.26  85003.83 45925.64  93182.45
2015.263       73306.79  57716.77  88896.82 49463.91  97149.68
2015.282       78975.88  63224.05  94727.71 54885.53 103066.23
2015.301       83368.51  67442.71  99294.31 59012.10 107724.93
2015.320       84148.31  68060.33 100236.30 59543.86 108752.76
2015.339       81426.24  65196.75  97655.74 56605.37 106247.11
2015.359       77443.50  61081.10  93805.90 52419.37 102467.63
2015.378       74775.69  58272.42  91278.97 49536.12 100015.27
2015.397       74558.00  57901.69  91214.32 49084.37 100031.64
2015.416       76095.25  59285.54  92904.96 50387.01 101803.48
2015.435       78060.88  61110.28  95011.48 52137.18 103984.59
2015.454       80180.84  63100.97  97260.72 54059.43 106302.25
2015.474       83822.54  66613.41 101031.67 57503.44 110141.64
2015.493       90712.50  73365.03 108059.98 64181.84 117243.17
2015.512      100614.62  83122.87 118106.38 73863.30 127365.95
2015.531      109996.21  92365.73 127626.69 83032.72 136959.70
2015.550      113344.54  95586.69 131102.39 86186.25 140502.83
2015.569      106822.66  88942.86 124702.47 79477.86 134167.47
2015.589       91762.34  73755.78 109768.90 64223.68 119301.00
2015.608       75016.97  56875.59  93158.36 47272.12 102761.83
2015.627       65240.68  46964.00  83517.37 37288.90  93192.47
2015.646       67389.62  48986.56  85792.69 39244.57  95534.68
2015.665       79501.06  60980.53  98021.58 51176.36 107825.75
2015.684       94341.82  75703.92 112979.72 65837.61 122846.03
2015.704      104738.56  85975.61 123501.51 76043.10 133434.01
2015.723      108388.65  89495.21 127282.10 79493.63 137283.68
2015.742      108375.06  89355.88 127394.24 79287.74 137462.38
2015.761      109260.33  90126.03 128394.63 79996.94 138523.71
2015.780      112408.56  93164.45 131652.67 82977.23 141839.89
2015.799      114746.16  95387.18 134105.13 85139.16 144353.16
2015.819      111991.74  92508.83 131474.64 82195.20 141788.27
2015.838      103303.51  83695.64 122911.38 73315.86 133291.16
2015.857       92995.07  73272.48 112717.66 62831.97 123158.17
2015.876       87624.60  67798.21 107450.99 57302.76 117946.44
2015.895       90935.62  71005.54 110865.70 60455.19 121416.04
2015.914      101024.88  80980.22 121069.54 70369.21 131680.54
2015.934      112068.57  91900.42 132236.72 81224.05 142913.10
2015.953      118900.25  98615.37 139185.12 87877.21 149923.29
2015.972      120396.94 100013.10 140780.77 89222.55 151571.32
2015.991      119001.71  98529.05 139474.37 87691.47 150311.95
2016.010      117346.47  96775.77 137917.18 85886.30 148806.65
2016.029      115418.48  94727.90 136109.06 83774.97 147061.99
2016.049      110873.10  90056.68 131689.51 79037.14 142709.05
2016.068      101934.77  81024.78 122844.76 69955.70 133913.84
2016.087       89905.85  68950.05 110861.65 57856.72 121954.98
2016.106       78799.43  57824.70  99774.16 46721.35 110877.51
2016.125       72389.82  51396.94  93382.69 40283.98 104495.65
2016.144       71351.98  50313.37  92390.59 39176.20 103527.76
2016.164       73003.82  51860.00  94147.65 40667.13 105340.51
2016.183       73773.35  52471.74  95074.96 41195.35 106351.36
2016.202       72159.45  50697.92  93620.97 39336.88 104982.02
2016.221       69690.29  48101.92  91278.66 36673.73 102706.85
2016.240       69256.12  47567.38  90944.87 36086.05 102426.20
2016.259       72415.52  50628.61  94202.44 39095.31 105735.74
2016.279       77962.67  56062.75  99862.59 44469.63 111455.71
2016.298       82809.41  60784.56 104834.26 49125.31 116493.51
2016.317       84304.26  62159.57 106448.94 50436.88 118171.63
2016.336       82086.07  59836.17 104335.97 48057.78 116114.36
2016.355       78121.18  55774.15 100468.21 43944.35 112298.01
2016.374       75078.43  52629.85  97527.01 40746.29 109410.57
2016.394       74429.74  51869.81  96989.66 39927.31 108932.17
2016.413       75756.42  53082.36  98430.48 41079.43 110433.41
2016.432       77713.76  54933.27 100494.26 42874.00 112553.53
2016.451       79746.92  56869.18 102624.66 44758.44 114735.40
2016.470       82971.40  59997.81 105944.99 47836.33 118106.47
2016.489       89212.90  66136.98 112288.81 53921.33 124504.46
2016.509       98741.12  75556.92 121925.32 63283.95 134198.29
2016.528      108602.08  85311.87 131892.29 72982.78 144221.39
2016.547      113413.17  90025.09 136801.25 77644.19 149182.15
2016.566      108734.00  85253.17 132214.84 72823.16 144644.85
2016.585       94827.00  71250.69 118403.30 58770.15 130883.84
2016.604       77727.28  54048.85 101405.70 41514.25 113940.30
2016.624       66170.44  42387.77  89953.11 29797.98 102542.90
2016.643       66126.31  42245.02  90007.61 29603.02 102649.60
2016.662       76895.42  52922.76 100868.09 40232.39 113558.45
2016.681       91855.81  67793.01 115918.60 55054.94 128656.67
2016.700      103392.61  79234.14 127551.07 66445.42 140339.79
2016.719      108144.16  83884.58 132403.74 71042.33 145245.99
2016.739      108422.65  84063.92 132781.39 71169.18 145676.13
2016.758      108911.01  84460.96 133361.05 71517.89 146304.12
2016.777      111773.52  87237.39 136309.66 74248.74 149298.30
2016.796      114600.56  89975.52 139225.60 76939.81 152261.31
2016.815      112965.28  88243.86 137686.70 75157.14 150773.43
2016.834      105155.15  80334.64 129975.66 67195.46 143114.84
2016.854       94653.85  69740.89 119566.80 56552.78 132754.92
2016.873       87985.16  62988.95 112981.38 49756.75 126213.58
2016.892       89719.06  64641.36 114796.75 51366.03 128072.08
2016.911       98965.92  73798.98 124132.85 60476.41 137455.42
2016.930      110299.28  85034.53 135564.04 71660.17 148938.39
2016.949      118099.93  92740.04 143459.82 79315.33 156884.53
2016.969      120437.17  94995.61 145878.74 81527.65 159346.69
2016.988      119320.41  93807.25 144833.57 80301.40 158339.42
2017.007      117619.63  92030.25 143209.00 78484.06 156755.19
2017.026      115874.87  90192.15 141557.58 76596.54 155153.19
2017.045      111987.83  86202.47 137773.20 72552.52 151423.15
2017.064      103841.95  77974.49 129709.41 64281.08 143402.82
2017.084       92119.32  66208.61 118030.03 52492.32 131746.33

因此,对于上述预测输出,高图功能无法正常工作,例如:

hchart(forecastweekly)

它给出错误:

  

as.Date.ts(。)出错:无法将ts时间转换为Date类

但是当我使用绘图功能时,它会提供正确的输出。我该如何处理这个错误?

在这里,你可以看到一个可重复的例子,取自Rob J. Hyndman的website

library(forecast)
gas <- ts(read.csv("http://robjhyndman.com/data/gasoline.csv", header=FALSE)
[,1], freq=365.25/7, start=1991+31/365.25)
gastbats <- tbats(gas)
fc2 <- forecast(gastbats, h=104)

plot(fc2) #It works
hchart(fc2) #It doesn't

问候!

0 个答案:

没有答案