Nel*_*son 5 r time-series forecasting
我每天都会观察到以下时间序列数据:
series <- c(10, 25, 8, 27, 18, 21, 12, 9, 31, 18, 8, 30, 14, 13, 10, 14,
14, 14, 6, 9, 22, 21, 22, 8, 7, 6, 22, 21, 36, 16, 2, 13, 23,
40, 12, 27, 18, 10, 11, 37, 44, 30, 40, 25, 13, 11, 58, 56, 46,
39, 28, 27, 19, 20, 97, 90, 70, 73, 30, 22, 97, 34)
Run Code Online (Sandbox Code Playgroud)
并希望tbats从R forecasts包中使用它.我还想用每周相关性对它进行建模:
library(forecast)
x.msts = msts(series,seasonal.periods = 7)
model <- tbats(x.msts)
# shows "--- loading profile ---"
Run Code Online (Sandbox Code Playgroud)
对模型进行检查/绘制可以str发现一个巨大的拟合方差4.9e+17.
而且,绘制预测未来,我们观察到大幅波动:
> forecast(model)$mean
Multi-Seasonal Time Series:
Start: 9 7
Seasonal Periods: 7
Data:
[1] 1.483789e+44 -1.399297e+42 -2.566455e+44 -1.374316e+43 -1.527758e+38
[6] 2.036194e+42 5.639596e+42 8.231600e+40 -2.578859e+41 -1.355840e+43
Run Code Online (Sandbox Code Playgroud)
这些估计是TBATS模型拟合程序的"正确"解决方案,还是forecast包装中有错误?如果不是一个错误,有人可以帮助我在数学上理解为什么这个看似正常的时间序列会产生这些估计吗?
这是我在简历上的第一篇文章,如果这应该是SO,请道歉!
我已经在github上提交了一份错误报告
还有一些人注意到我没有使用多个季节性因素,所以我想在这里说明这个bug仍然是一个问题:
x2.msts <- msts(series,seasonal.periods = c(7,30))
model_x2_1 <- tbats(x2.msts) # high variance
model_x2_2 <- tbats( series, seasonal.periods = c(7,30) ) # also high variance
Run Code Online (Sandbox Code Playgroud)
这可能与此处描述的问题相同,因此原因可能是预测包中的错误。我不确定以下替代方案是否会给您带来所需的结果,但您可以 series按原样保留并放入以下seasonal.periods=7调用中tbats:
library(forecast)
series <- c(10, 25, 8, 27, 18, 21, 12, 9, 31, 18, 8, 30, 14, 13, 10, 14,
14, 14, 6, 9, 22, 21, 22, 8, 7, 6, 22, 21, 36, 16, 2, 13, 23,
40, 12, 27, 18, 10, 11, 37, 44, 30, 40, 25, 13, 11, 58, 56, 46,
39, 28, 27, 19, 20, 97, 90, 70, 73, 30, 22, 97, 34)
x.msts <- msts(series,seasonal.periods = 7)
model_1 <- tbats(x.msts)
model_2 <- tbats( series, seasonal.periods = 7 )
Run Code Online (Sandbox Code Playgroud)
的方差model_2比 的方差好得多model_1:
> str(model_1)
List of 19
$ lambda : num 0.21
$ alpha : num 0.374
$ beta : NULL
$ damping.parameter: NULL
$ gamma.values : NULL
$ ar.coefficients : num [1:2] 1.296 -0.911
$ ma.coefficients : num [1:2] -1.62 0.98
$ likelihood : num 549
$ optim.return.code: int 0
$ variance : num 4.9e+17
$ AIC : num 571
$ parameters :List of 2
..$ vect : num [1:6] 0.21 0.374 1.296 -0.911 -1.615 ...
..$ control:List of 6
.. ..$ use.beta : logi FALSE
.. ..$ use.box.cox : logi TRUE
.. ..$ use.damping : logi FALSE
.. ..$ length.gamma: num 0
.. ..$ p : int 2
.. ..$ q : int 2
$ seed.states : num [1:5, 1] 4.16 0 0 0 0
$ fitted.values : Time-Series [1:62] from 1 to 9.71: 19.97 19.28 4.53 21.83 56.15 ...
..- attr(*, "msts")= num 7
$ errors : Time-Series [1:62] from 1 to 9.71: -1.206 0.496 0.828 0.415 -2.354 ...
..- attr(*, "msts")= num 7
$ x : num [1:5, 1:62] 3.71 -1.21 0 -1.21 0 ...
$ seasonal.periods : NULL
$ y : Time-Series [1:62] from 1 to 9.71: 10 25 8 27 18 21 12 9 31 18 ...
..- attr(*, "msts")= num 7
$ call : language tbats(y = x.msts)
- attr(*, "class")= chr "bats"
>
Run Code Online (Sandbox Code Playgroud)
。
> str(model_2)
List of 23
$ lambda : num 0.198
$ alpha : num 0.198
$ beta : NULL
$ damping.parameter: NULL
$ gamma.one.values : num -0.0157
$ gamma.two.values : num 0.00991
$ ar.coefficients : NULL
$ ma.coefficients : NULL
$ likelihood : num 553
$ optim.return.code: int 0
$ variance : num 0.969
$ AIC : num 571
$ parameters :List of 2
..$ vect : num [1:4] 0.19842 0.19782 -0.0157 0.00991
..$ control:List of 6
.. ..$ use.beta : logi FALSE
.. ..$ use.box.cox : logi TRUE
.. ..$ use.damping : logi FALSE
.. ..$ length.gamma: int 2
.. ..$ p : num 0
.. ..$ q : num 0
$ seed.states : num [1:5, 1] 4.1851 0.3176 0.0103 -0.5806 0.4447
$ fitted.values : Time-Series [1:62] from 1 to 62: 25.1 20 11.1 10.2 24.3 ...
$ errors : Time-Series [1:62] from 1 to 62: -1.594 0.41 -0.507 1.697 -0.552 ...
$ x : num [1:5, 1:62] 3.87 -0.231 0.456 -0.626 -0.125 ...
$ seasonal.periods : num 7
$ k.vector : int 2
$ y : Time-Series [1:62] from 1 to 62: 10 25 8 27 18 21 12 9 31 18 ...
$ p : num 0
$ q : num 0
$ call : language tbats(y = series, seasonal.periods = 7)
- attr(*, "class")= chr [1:2] "tbats" "bats"
>
Run Code Online (Sandbox Code Playgroud)