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). This can be a number of steps, or
text such as "1 year" for the number of steps covering that calendar
period after the end of the data.
The number of replications.
Call
set.seed() before generate() instead.
Additional arguments for individual simulation methods.
Please use
bootstrap_iid() or bootstrap_block() to wrap the model instead.
Please use
bootstrap_block()'s block_size argument instead.
Innovations are sampled by the model's assumed error distribution, or
resampled from the model's residuals for models modified with
bootstrap_iid() or bootstrap_block(). 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 4 [1M]
#> # Key: .model, .rep [5]
#> .model index .rep .sim
#> <chr> <mth> <chr> <dbl>
#> 1 lm 1974 Jan 1 2187.
#> 2 lm 1974 Feb 1 1892.
#> 3 lm 1974 Mar 1 2118.
#> 4 lm 1974 Apr 1 1724.
#> 5 lm 1974 May 1 1419.
#> 6 lm 1974 Jun 1 1211.
#> 7 lm 1974 Jul 1 1332.
#> 8 lm 1974 Aug 1 1102.
#> 9 lm 1974 Sep 1 1053.
#> 10 lm 1974 Oct 1 1722.
#> # ℹ 350 more rows