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

问题描述

我有一个像这样的时间序列 t值 1 12 2 12 3 0 4 0 5 0 6 0 7 0 我期望acf1等于0.443,但改正精度函数会产生null。代码如下:

df = data.frame("t" = 1:7,"value" = c(12,12,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)

为什么会这样?

解决方法

ACF1中的accuracy()列是残差的第一个自相关。您期望的ACF1为0.443,这是您数据的第一个自相关,可以通过以下方式获得:

library(feasts)
#> Loading required package: fabletools
df = data.frame("t" = 1:7,"value" = c(12,12,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创建