[Experimental]

Wraps a fitted model (or a model column from a mable) so that forecast() produces its distribution from simulated sample paths (via generate()) instead of closed-form/analytical results. Innovations are drawn independently at each time point, parametrically from the model's assumed error distribution, identically to calling generate() on the model directly. This is primarily useful for models (or transformations) whose forecast distribution has no closed form, and for producing forecasts that are directly comparable to bootstrap_iid()/bootstrap_block() (which only differ in how innovations are drawn).

simulate_iid(model, times = 5000)

Arguments

model

A fitted model, typically a model column from a mable modified with dplyr::mutate() (e.g. mutate(ets = simulate_iid(ets))). Alternatively, an unfitted model specification can be wrapped directly inside model() (e.g. model(ets = simulate_iid(ETS(Trips)))), in which case each series is fitted and simulated independently, identically to wrapping each series' mdl_ts individually.

times

The number of simulated sample paths to generate.

Examples

library(fable)
library(tsibbledata)
library(dplyr)
aus_production %>%
  model(ets = ETS(Beer)) %>%
  mutate(ets = simulate_iid(ets, times = 1000)) %>%
  forecast()
#> # A fable: 8 x 4 [1Q]
#> # Key:     .model [1]
#>   .model Quarter         Beer .mean
#>   <chr>    <qtr>       <dist> <dbl>
#> 1 ets    2010 Q3 sample[1000]  405.
#> 2 ets    2010 Q4 sample[1000]  481.
#> 3 ets    2011 Q1 sample[1000]  417.
#> 4 ets    2011 Q2 sample[1000]  383.
#> 5 ets    2011 Q3 sample[1000]  404.
#> 6 ets    2011 Q4 sample[1000]  479.
#> 7 ets    2012 Q1 sample[1000]  416.
#> 8 ets    2012 Q2 sample[1000]  382.

# Equivalently, applied to the model specification before fitting:
aus_production %>%
  model(ets = simulate_iid(ETS(Beer), times = 1000)) %>%
  forecast()
#> # A fable: 8 x 4 [1Q]
#> # Key:     .model [1]
#>   .model Quarter         Beer .mean
#>   <chr>    <qtr>       <dist> <dbl>
#> 1 ets    2010 Q3 sample[1000]  405.
#> 2 ets    2010 Q4 sample[1000]  481.
#> 3 ets    2011 Q1 sample[1000]  417.
#> 4 ets    2011 Q2 sample[1000]  383.
#> 5 ets    2011 Q3 sample[1000]  404.
#> 6 ets    2011 Q4 sample[1000]  479.
#> 7 ets    2012 Q1 sample[1000]  415.
#> 8 ets    2012 Q2 sample[1000]  382.