tidyverts / fabletools

General fable features useful for extension packages
http://fabletools.tidyverts.org/
89 stars 31 forks source link

is_null_model applied in a mable #131

Closed robjhyndman closed 4 years ago

robjhyndman commented 4 years ago

I would have thought this would give me a TRUE

library(tidyverse)
library(tsibble)
#> 
#> Attaching package: 'tsibble'
#> The following object is masked from 'package:dplyr':
#> 
#>     id
library(fable)
#> Loading required package: fabletools
#> 
#> Attaching package: 'fabletools'
#> The following object is masked from 'package:stats':
#> 
#>     decompose

tsibble(
    date = as.Date("2017-01-01") + 0:3,
    value = 3
  ) %>% model(
    ets = ETS(value),
  ) %>%
  mutate(
    test = is_null_model(ets),
  )
#> Using `date` as index variable.
#> Warning: 1 error encountered for ets
#> [1] missing value where TRUE/FALSE needed
#> # A mable: 1 x 2
#>   ets          test 
#>   <model>      <lgl>
#> 1 <NULL model> FALSE

Created on 2019-10-18 by the reprex package (v0.3.0)

mitchelloharawild commented 4 years ago

is_null_model wasn't written for vectorised usage, however I see assumption/usage.

robjhyndman commented 4 years ago

My use case is something like this where the chosen model is not fitted due to very short series (or some other issue):

tsibble(
    date = as.Date("2017-01-01") + 0:3,
    value = 3
  ) %>% model(
    ets = ETS(value),
    naive = NAIVE(value)
  ) %>%
  mutate(
    fred = if_else(is_null_model(ets), naive, ets)
  )

Is there a better alternative?

mitchelloharawild commented 4 years ago

That code looks fine.