从 fabletools 包中的精度函数获取空结果

Getting null results from the accuracy function in fabletools package

我有一个看起来像这样的时间序列 t值 1 12 2 12 3 0 4 0 5 0 6 0 7 0 我希望 acf1 等于 0.443,但准确度函数却产生空值。代码如下:

df = data.frame("t" = 1:7, "value" = c(12, 12, 0, 0, 0, 0, 0))
tsb = df %>%
as_tsibble(index = t)
md = tsb %>% model(arima = ARIMA(value ~ PDQ(period = 4), stepwise = F))

fc = md %>% forecast(h = 4)

accuracy(fc, tsb)

为什么会这样?

accuracy() 中的 ACF1 列是第一个 auto-correlation 残差。您期望的0.443的ACF1是您数据的第一个auto-correlation,可以通过以下方式获得:

library(feasts)
#> Loading required package: fabletools
df = data.frame("t" = 1:7, "value" = c(12, 12, 0, 0, 0, 0, 0))
tsb = df %>%
  as_tsibble(index = t)
tsb %>% ACF(lag_max = 1)
#> Response variable not specified, automatically selected `var = value`
#> # A tsibble: 1 x 2 [1]
#>     lag   acf
#>   <lag> <dbl>
#> 1     1 0.443

reprex package (v0.3.0)

于 2020-08-13 创建

您使用的第二个问题是 accuracy() 预测需要未来数据来计算预测误差。 fc 中的预测与 tsb 提供的时间不匹配,因此无法计算预测误差。

library(tsibble)
library(dplyr)
library(fable)

md = tsb %>% model(arima = ARIMA(value ~ PDQ(period = 4), stepwise = F))
fc = md %>% forecast(h = 4)

# Make up some future data for evaluating forecast accuracy
tsb_future <- new_data(tsb, 4) %>% mutate(value = rnorm(4))
# Compute the accuracy of the forecasts against the tsb_future scenario
accuracy(fc, tsb_future)
#> # A tibble: 1 x 9
#>   .model .type     ME  RMSE   MAE   MPE  MAPE  MASE    ACF1
#>   <chr>  <chr>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>   <dbl>
#> 1 arima  Test  -0.779  1.09 0.975   100   100   NaN -0.0478

reprex package (v0.3.0)

于 2020-08-13 创建