0

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

Mushroom
  • 17
  • 3

1 Answers1

0

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)

Rob Hyndman
  • 30,301
  • 7
  • 73
  • 85
  • Thanks! This particular addition of points works, though I still wonder why it doesn't when I add two 0s at the end? That is, if I have value = c(12, 12, 0, 0, 0, 0, 0, 0, 0), I still get null for ACF1. – Mushroom Aug 16 '20 at 20:34
  • Because all the forecasts are zero, and all the actuals are zero, so all the errors are zero. You are asking for the autocorrelations of a series of zeros which is undefined. – Rob Hyndman Aug 16 '20 at 22:31