Use a model's fitted distribution to simulate additional data with similar
behaviour to the response. This is a tidy implementation of
stats::simulate()
.
A mable.
The data to be generated (time index and exogenous regressors)
The simulation horizon (can be used instead of new_data
for regular
time series with no exogenous regressors).
The number of replications.
The seed for the random generation from distributions.
Additional arguments for individual simulation methods.
If TRUE, then forecast distributions are computed using simulation with resampled errors.
The bootstrap block size specifies the number of contiguous residuals to be taken in each bootstrap sample.
Innovations are sampled by the model's assumed error distribution.
If bootstrap
is TRUE
, innovations will be sampled from the model's
residuals. If new_data
contains the .innov
column, those values will be
treated as innovations for the simulated paths..
library(fable)
library(dplyr)
UKLungDeaths <- as_tsibble(cbind(mdeaths, fdeaths), pivot_longer = FALSE)
UKLungDeaths %>%
model(lm = TSLM(mdeaths ~ fourier("year", K = 4) + fdeaths)) %>%
generate(UKLungDeaths, times = 5)
#> # A tsibble: 360 x 6 [1M]
#> # Key: .model, .rep [5]
#> .model .rep index mdeaths fdeaths .sim
#> <chr> <chr> <mth> <dbl> <dbl> <dbl>
#> 1 lm 1 1974 Jan 2134 901 2238.
#> 2 lm 1 1974 Feb 1863 689 1856.
#> 3 lm 1 1974 Mar 1877 827 2310.
#> 4 lm 1 1974 Apr 1877 677 1623.
#> 5 lm 1 1974 May 1492 522 1457.
#> 6 lm 1 1974 Jun 1249 406 946.
#> 7 lm 1 1974 Jul 1280 441 1164.
#> 8 lm 1 1974 Aug 1131 393 1070.
#> 9 lm 1 1974 Sep 1209 387 1106.
#> 10 lm 1 1974 Oct 1492 582 1451.
#> # ℹ 350 more rows