1

This code works correctly

require(fable)   
it <-  tsibbledata::global_economy %>%
    filter(Country == "Italy")
fm0 <-  model(.data = it, 
    ARIMA(log(GDP) ~ Population), 
    ETS(log(GDP)))

Next one is not expected to work

fm1 <-  model(.data = it, 
    ARIMA(log(GDP) ~ Population + pdq(3,1,7) +PDQ(5,1,1)),
    ETS(log(GDP)))

Clearly it does not work because of ARIMA model. ETS works fine

I could do:

fm2 <-  try(
    model(.data = it, 
    ARIMA(log(GDP) ~ Population + pdq(3,1,7) +PDQ(5,1,1)), 
    ETS(log(GDP))))

But this will make both models to fail

I would like something like

fm3 <-  try(
    model(.data = it, 
    try(ARIMA(log(GDP) ~ Population + pdq(3,1,7) +PDQ(5,1,1))), 
    ETS(log(GDP))))

so that fm3 contains the correct results for ETS and an object of class 'try-error' for ARIMA

Possibly modifying fablelite:::estimate so that it can handle errors could be a solution?

Any help would be very much appreciated

Steffen Moritz
  • 7,277
  • 11
  • 36
  • 55
Andrea
  • 593
  • 2
  • 8

1 Answers1

0

Great suggestion, this is a feature that we've been thinking about for a little while now (https://github.com/tidyverts/fable/issues/74).

I've added a .safely argument to the model() argument which will return formatted warnings and return a null_model() rather than error (https://github.com/tidyverts/fablelite/commit/1c7dccd7e48211125cf566bcce9ba8c9fc4e47ce).

A null_model() is a model without estimation, and all model methods (forecast(), accuracy(), etc.) will give appropriately structured NA values.

I've set .safely=TRUE as default, so the above code now gives:

library(fable)
library(tidyverse)
it <-  tsibbledata::global_economy %>%
  filter(Country == "Italy")
fm1 <-  model(.data = it, 
              ARIMA(log(GDP) ~ Population + pdq(3,1,7) +PDQ(5,1,1)),
              ETS(log(GDP)))
#> Warning: 1 error encountered for ARIMA(log(GDP) ~ Population + pdq(3, 1, 7) + PDQ(5, 1, 1))
#> [1] There are no ARIMA models to choose from after imposing the `order_constraint`, please consider allowing more models.
fm1
#> # A mable: 1 x 3
#> # Key:     Country [1]
#>   Country `ARIMA(log(GDP) ~ Population + pdq(3, 1, 7) + PD… `ETS(log(GDP))`
#>   <fct>   <model>                                           <model>        
#> 1 Italy   <NULL model>                                      <ETS(M,Ad,N)>

Created on 2019-05-30 by the reprex package (v0.2.1)