在ts的移动平均值上使用'残差'的错误

问题描述 投票:0回答:1

我一直在使用ts对象进行预测。为了测试移动平均线的准确性,我使用了以下代码:

fixt_ma <- ma(fixtures_training, 3)
residuals(fixt_ma)
acc_fixt_ma <- accuracy(fixt_ma, fixtures_test)

fixtures_training的输入

structure(c(161L, 338L, 393L, 405L, 439L, 386L, 442L, 406L, 413L, 
421L), .Tsp = c(2019.48076923077, 2019.65384615385, 52), class = "ts")

当我使用residuals(fixt_ma)函数时,或者当我编写residuals $ fixt_ma之类的代码时,出现以下错误:

Error: $ operator is invalid for atomic vectors

有人知道我该如何解决吗?

vector time-series moving-average forecast
1个回答
0
投票

forecast::ma进行移动平均平滑。它不是模型,因此没有残差。

也许您想要一个MA(3)模型,在这种情况下,您可以使用

fixt_ma <- Arima(fixtures_training, order=c(0,0,3))

然后residuals()将起作用:

residuals(fixt_ma)
#> Time Series:
#> Start = c(2019, 26) 
#> End = c(2019, 35) 
#> Frequency = 52 
#>  [1] -79.553356  99.757891 -16.836345  -8.949918  42.906861   4.752855
#>  [7]  39.762007 -29.453682  47.281713  11.804971

但是accuracy()使用您问题中的代码会出错。如果要在测试集上进行预测准确性度量,则首先必须生成预测:

fc_ma <- forecast(fixt_ma, h=length(fixtures_test))
acc_fixt_ma <- accuracy(fc_ma, fixtures_test)
© www.soinside.com 2019 - 2024. All rights reserved.