Simulates future paths from a dataset using a fitted model. 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.
# S3 method for RW
generate(x, new_data, bootstrap = FALSE, ...)
A fitted model.
A tsibble containing the time points and exogenous regressors to produce forecasts for.
If TRUE
, then forecast distributions are computed using simulation with resampled errors.
Other arguments passed to methods
as_tsibble(Nile) %>%
model(NAIVE(value)) %>%
generate()
#> # A tsibble: 2 x 4 [1Y]
#> # Key: .model, .rep [1]
#> .model .rep index .sim
#> <chr> <chr> <dbl> <dbl>
#> 1 NAIVE(value) 1 1971 685.
#> 2 NAIVE(value) 1 1972 881.
library(tsibbledata)
aus_production %>%
model(snaive = SNAIVE(Beer ~ lag("year"))) %>%
generate()
#> # A tsibble: 8 x 4 [1Q]
#> # Key: .model, .rep [1]
#> .model .rep Quarter .sim
#> <chr> <chr> <qtr> <dbl>
#> 1 snaive 1 2010 Q3 402.
#> 2 snaive 1 2010 Q4 507.
#> 3 snaive 1 2011 Q1 412.
#> 4 snaive 1 2011 Q2 346.
#> 5 snaive 1 2011 Q3 402.
#> 6 snaive 1 2011 Q4 466.
#> 7 snaive 1 2012 Q1 443.
#> 8 snaive 1 2012 Q2 357.