【问题标题】:Error using 'residuals' on moving average for ts在 ts 的移动平均值上使用“残差”时出错
【发布时间】:2019-11-29 14:34:19
【问题描述】:

我一直致力于使用 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】:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 2014-02-17
      • 2018-07-23
      • 2023-03-25
      相关资源
      最近更新 更多