Error in seasonal_naive model

Hi, and welcome!

A reproducible example, called a reprex is very helpful in attracting more helpful answers. Your code snippet comes close but violates the R zen of lazy evaluation. Here's what a reprex would look like.

library(tsibble)
library(tidyverse)
library(tsibbledata)
library(fable)
#> Loading required package: fabletools
library(forecast)
#> Registered S3 method overwritten by 'xts':
#>   method     from
#>   as.zoo.xts zoo
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
#> Registered S3 methods overwritten by 'forecast':
#>   method             from    
#>   fitted.fracdiff    fracdiff
#>   residuals.fracdiff fracdiff
#> 
#> Attaching package: 'forecast'
#> The following objects are masked from 'package:fabletools':
#> 
#>     GeomForecast, StatForecast
australia <- global_economy %>% filter(Country == "Australia")

australia_fit <- australia %>% 
  model(naive_seasonal = SNAIVE(GDP, lag("year")))
#> Warning: 1 error encountered for naive_seasonal
#> [1] Non-seasonal model specification provided, use RW() or provide a different lag specification.

Created on 2020-01-17 by the reprex package (v0.3.0)

The error is thrown by fable::model which takes a data structure such as a tstibble, model definitions, and an optional flag and produces a mable.

It's always a good idea to start with the example from the package function's help()

library(tsibble)
library(tidyverse)
library(tsibbledata)
library(fable)
#> Loading required package: fabletools
library(forecast)
#> Registered S3 method overwritten by 'xts':
#>   method     from
#>   as.zoo.xts zoo
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
#> Registered S3 methods overwritten by 'forecast':
#>   method             from    
#>   fitted.fracdiff    fracdiff
#>   residuals.fracdiff fracdiff
#> 
#> Attaching package: 'forecast'
#> The following objects are masked from 'package:fabletools':
#> 
#>     GeomForecast, StatForecast
# Training an ETS(M,Ad,A) model to Australian beer production
aus_production %>%
  model(ets = ETS(log(Beer) ~ error("M") + trend("Ad") + season("A")))
#> # A mable: 1 x 1
#>   ets          
#>   <model>      
#> 1 <ETS(M,Ad,A)>

Created on 2020-01-17 by the reprex package (v0.3.0)

So isn't the obvious question is what is SNAIVE and what does it want?

Well, one possibility is something other than year.

Take a look at the formal arguments and see how your case differs from the example.

1 Like