forecast :: thetaf错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了forecast :: thetaf错误相关的知识,希望对你有一定的参考价值。
我目前在预测包8.2和thetaf函数方面遇到问题:
dat<- structure(c(5, 0, 5, 0, 0, 2, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0, 2, 0, 1,
0, 2.1, 0, 2, 0, 1, 0, 0, 0, 2.5, 2, 2, 0, 1.7, 0, 1.5, 0, 1,
0, 0, 0, 2.5, 0), .Tsp = c(1999, 2003.91666666667, 12), class = "ts")
library(forecast)
thetaf(dat,h = 1)$mean
出现以下错误
Error in ets(object, lambda = lambda, allow.multiplicative.trend = allow.multiplicative.trend, :
y should be a univariate time series
Additional: Warnings:
1: In ets(x, "ANN", alpha = alpha, opt.crit = "mse", lambda = lambda, :
Missing values encountered. Using longest contiguous portion of time series
2: In fit$call <- match.call() : ...
该错误与频率有关。如果它是1而不是12然后它工作。我没有看到为什么这会导致错误的原因。有任何想法吗?
答案
当应用于季节性数据时,theta方法使用乘法经典分解来消除季节性。在这种情况下,分解失败:
> decompose(dat, type="multiplicative")
$x
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1999 5.0 0.0 5.0 0.0 0.0 2.0 0.0 0.0 0.0 0.0 0.0 0.0
2000 4.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
2001 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.9 0.0 2.0 0.0
2002 1.0 0.0 2.1 0.0 2.0 0.0 1.0 0.0 0.0 0.0 2.5 2.0
2003 2.0 0.0 1.7 0.0 1.5 0.0 1.0 0.0 0.0 0.0 2.5 0.0
$seasonal
Jan Feb Mar Apr May Jun Jul Aug
1999 5.5063443 0.0000000 1.2804721 0.0000000 1.2020131 0.0000000 0.2851915 0.0000000
2000 5.5063443 0.0000000 1.2804721 0.0000000 1.2020131 0.0000000 0.2851915 0.0000000
2001 5.5063443 0.0000000 1.2804721 0.0000000 1.2020131 0.0000000 0.2851915 0.0000000
2002 5.5063443 0.0000000 1.2804721 0.0000000 1.2020131 0.0000000 0.2851915 0.0000000
2003 5.5063443 0.0000000 1.2804721 0.0000000 1.2020131 0.0000000 0.2851915 0.0000000
Sep Oct Nov Dec
1999 0.7674245 0.0000000 2.1696136 0.7889410
2000 0.7674245 0.0000000 2.1696136 0.7889410
2001 0.7674245 0.0000000 2.1696136 0.7889410
2002 0.7674245 0.0000000 2.1696136 0.7889410
2003 0.7674245 0.0000000 2.1696136 0.7889410
$trend
Jan Feb Mar Apr May Jun Jul Aug
1999 NA NA NA NA NA NA 0.9583333 0.9166667
2000 0.3333333 0.3333333 0.3333333 0.3333333 0.3333333 0.3333333 0.1666667 0.0000000
2001 0.0000000 0.0000000 0.0375000 0.0750000 0.1583333 0.2416667 0.2833333 0.3250000
2002 0.7083333 0.7500000 0.7125000 0.6750000 0.6958333 0.8000000 0.9250000 0.9666667
2003 0.8916667 0.8916667 0.8916667 0.8916667 0.8916667 0.8083333 NA NA
Sep Oct Nov Dec
1999 0.7083333 0.5000000 0.5000000 0.4166667
2000 0.0000000 0.0000000 0.0000000 0.0000000
2001 0.4125000 0.5000000 0.5833333 0.6666667
2002 0.9500000 0.9333333 0.9125000 0.8916667
2003 NA NA NA NA
$random
Jan Feb Mar Apr May Jun Jul Aug
1999 NA NaN NA NaN NA NA 0.0000000 NaN
2000 2.1793043 NaN 0.0000000 NaN 0.0000000 NaN 0.0000000 NaN
2001 NaN NaN 0.0000000 NaN 0.0000000 NaN 0.0000000 NaN
2002 0.2563887 NaN 2.3017827 NaN 2.3911982 NaN 3.7907196 NaN
2003 0.4073466 NaN 1.4889369 NaN 1.3995214 NaN NA NaN
Sep Oct Nov Dec
1999 0.0000000 NaN 0.0000000 0.0000000
2000 NaN NaN NaN NaN
2001 2.8430397 NaN 1.5802682 0.0000000
2002 0.0000000 NaN 1.2627714 2.8430397
2003 NA NaN NA NA
$figure
[1] 5.5063443 0.0000000 1.2804721 0.0000000 1.2020131 0.0000000 0.2851915 0.0000000
[9] 0.7674245 0.0000000 2.1696136 0.7889410
$type
[1] "multiplicative"
attr(,"class")
[1] "decomposed.ts"
问题出现是因为4月,6月,8月和10月的季节性指数为零,因此除以季节性指数就会产生NaN
值。
我已经解决了问题(在预测包的v8.3中),当发生这种情况时,继续使用theta方法的非季节性版本。
以上是关于forecast :: thetaf错误的主要内容,如果未能解决你的问题,请参考以下文章
Temporal Fusion Transformersfor Interpretable Multi-horizon Time Series Forecasting代码解读(tensoreflow)