r-tslm()模型的forecast()如何决定要预测的周期



这里的h值到底发生了什么?如果你能给我指一下描述这一点的文档,我将不胜感激!感谢

library(forecast)
model <- tslm(USAccDeaths ~ trend + season)
forecast(model)                               # returns 12 months of forecasts
forecast(model, h=0)                          # returns  2 months of forecasts
forecast(model, h=1)                          # returns  1 month  of forecasts
forecast(model, h=2)                          # returns  2 months of forecasts (same as h=0)

默认的预测期是10个月,而不是12个月。h=0是一个错误,我已经在中修复了它https://github.com/robjhyndman/forecast/commit/4ed33c167822ba503bc4a6fdcac2b04cd5018459

所有其他预测范围(1、2、…(均按预期运行。

library(forecast)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
model <- tslm(USAccDeaths ~ trend + season)
forecast(model)
#>          Point Forecast    Lo 80     Hi 80    Lo 95     Hi 95
#> Jan 1979       7557.275 6917.525  8197.025 6569.565  8544.985
#> Feb 1979       6797.108 6157.358  7436.858 5809.399  7784.818
#> Mar 1979       7575.608 6935.858  8215.358 6587.899  8563.318
#> Apr 1979       7788.608 7148.858  8428.358 6800.899  8776.318
#> May 1979       8637.608 7997.858  9277.358 7649.899  9625.318
#> Jun 1979       9108.608 8468.858  9748.358 8120.899 10096.318
#> Jul 1979       9966.108 9326.358 10605.858 8978.399 10953.818
#> Aug 1979       9262.442 8622.692  9902.192 8274.732 10250.151
#> Sep 1979       8213.608 7573.858  8853.358 7225.899  9201.318
#> Oct 1979       8503.442 7863.692  9143.192 7515.732  9491.151
forecast(model, h=0)
#> Error in forecast.lm(model, h = 0): The forecast horizon must be at least 1.
forecast(model, h=1)
#>          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
#> Jan 1979       7557.275 6917.525 8197.025 6569.565 8544.985
forecast(model, h=2)
#>          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
#> Jan 1979       7557.275 6917.525 8197.025 6569.565 8544.985
#> Feb 1979       6797.108 6157.358 7436.858 5809.399 7784.818

创建于2022-08-31由reprex包(v2.0.1(

最新更新