rforecastingfable

Null result for ACF1 from accuracy function


I fit a naive model to a time series and got null for the ACF1 column. I thought it should always have a numerical result since it's just a correlation? Why is this null? Following is my code:

library('fable')
library('feasts')
library('dplyr')

df = data.frame("t" = 1:7, "value" = c(12, 12, 0, 0, 0, 0, 0))
tsb = df %>%
  as_tsibble(index = t)
train = tsb %>% filter(t < 6)

md = train %>% model(naive = NAIVE(value))
fc = md %>% forecast(h = 4)
accuracy(fc, tsb)

Thanks!

P.s.: This is a follow-up question for this question: Getting null results from the accuracy function in fabletools package


Solution

  • You have four forecasts, but only 2 values in the test set, so accuracy can only work with the first 2 forecasts. That gives it 2 forecast errors, and it is not possible to compute an autocorrelation from 2 values.

    Here is an example with four values in the test set:

    library(fable)
    library(dplyr)
    
    tsb <- data.frame(
        t = 1:9,
        value = c(12, 12, 0, 0, 0, 0, 0, 1, 1)
      ) %>%
      as_tsibble(index = t)
    
    md <- tsb %>%
      filter(t < 6) %>%
      model(naive = NAIVE(value))
    md %>%
      forecast(h = 4) %>%
      accuracy(data = tsb)
    #> # A tibble: 1 x 9
    #>   .model .type    ME  RMSE   MAE   MPE  MAPE  MASE  ACF1
    #>   <chr>  <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
    #> 1 naive  Test    0.5 0.707   0.5   100   100 0.167  0.25
    

    Created on 2020-08-16 by the reprex package (v0.3.0)