Reset random seeds stored in a model object.
When new_seeds
is NULL
(the default),
the new seeds are generated randomly; otherwise
they are taken from new_seeds
.
Arguments
- mod
An object of class
"bage_mod"
, created withmod_pois()
,mod_binom()
, ormod_norm()
.- new_seeds
NULL
(the default) or a list of integers with names"seed_components"
"seed_augment"
,"seed_forecast_components"
, and"seed_forecast_augment"
.
Details
When an object of class "bage_mod"
is first created,
values are generated four four random seeds:
seed_components
seed_augment
seed_forecast_components
seed_forecast_augment
When fit()
, components()
, augment()
,
and forecast()
are called on the model object,
the seeds are used internally to ensure that
he same inputs generate the same outputs, even
when the outputs involve random draws.
End users are unlikely to call set_seeds()
in
a data analysis, though it may occasionally by useful
when building a simulation from scratch.
See also
report_sim()
Do a simulation study. (report_sim()
callsset_seeds()
internally.)mod_pois()
,mod_binom()
,mod_norm()
Specify a modelfit()
Fit a modelunfit()
Reset model, deleting estimates
Examples
## fit model
mod <- mod_pois(injuries ~ age,
data = nzl_injuries,
exposure = popn) |>
fit()
## call 'components()'
components(mod)
#> # A tibble: 15 × 4
#> term component level .fitted
#> <chr> <chr> <chr> <rdbl<1000>>
#> 1 (Intercept) effect (Intercept) -2.5 (-5.1, 0.19)
#> 2 age effect 0-4 -2.4 (-5.2, 0.21)
#> 3 age effect 5-9 -3.9 (-6.2, -1.5)
#> 4 age effect 10-14 -4.9 (-7.6, -1.9)
#> 5 age effect 15-19 -5.1 (-7.9, -2.3)
#> 6 age effect 20-24 -5.1 (-7.9, -2.3)
#> 7 age effect 25-29 -5.2 (-8, -2.4)
#> 8 age effect 30-34 -5.3 (-8.1, -2.5)
#> 9 age effect 35-39 -5.3 (-8.3, -2.6)
#> 10 age effect 40-44 -5.5 (-8.5, -2.7)
#> 11 age effect 45-49 -5.4 (-8.5, -2.6)
#> 12 age effect 50-54 -5.5 (-8.6, -2.6)
#> 13 age effect 55-59 -5.5 (-8.6, -2.4)
#> 14 age hyper sd 0.96 (0.31, 3.1)
#> 15 disp disp disp 1.3 (0.47, 4.3)
## call 'components()' again - same results
components(mod)
#> # A tibble: 15 × 4
#> term component level .fitted
#> <chr> <chr> <chr> <rdbl<1000>>
#> 1 (Intercept) effect (Intercept) -2.5 (-5.1, 0.19)
#> 2 age effect 0-4 -2.4 (-5.2, 0.21)
#> 3 age effect 5-9 -3.9 (-6.2, -1.5)
#> 4 age effect 10-14 -4.9 (-7.6, -1.9)
#> 5 age effect 15-19 -5.1 (-7.9, -2.3)
#> 6 age effect 20-24 -5.1 (-7.9, -2.3)
#> 7 age effect 25-29 -5.2 (-8, -2.4)
#> 8 age effect 30-34 -5.3 (-8.1, -2.5)
#> 9 age effect 35-39 -5.3 (-8.3, -2.6)
#> 10 age effect 40-44 -5.5 (-8.5, -2.7)
#> 11 age effect 45-49 -5.4 (-8.5, -2.6)
#> 12 age effect 50-54 -5.5 (-8.6, -2.6)
#> 13 age effect 55-59 -5.5 (-8.6, -2.4)
#> 14 age hyper sd 0.96 (0.31, 3.1)
#> 15 disp disp disp 1.3 (0.47, 4.3)
## reset seeds
mod <- set_seeds(mod)
## calling 'set_seeds' unfits the model
is_fitted(mod)
#> [1] FALSE
## so we fit it again
mod <- fit(mod)
## when we call components, we get
## different results from earlier
components(mod)
#> # A tibble: 15 × 4
#> term component level .fitted
#> <chr> <chr> <chr> <rdbl<1000>>
#> 1 (Intercept) effect (Intercept) -2.5 (-5, 0.24)
#> 2 age effect 0-4 -2.4 (-5.1, 0.19)
#> 3 age effect 5-9 -3.9 (-6.6, -1.6)
#> 4 age effect 10-14 -4.8 (-7.9, -1.8)
#> 5 age effect 15-19 -5.1 (-7.8, -2.2)
#> 6 age effect 20-24 -5.1 (-8, -2.3)
#> 7 age effect 25-29 -5.4 (-8.3, -2.5)
#> 8 age effect 30-34 -5.4 (-8.4, -2.4)
#> 9 age effect 35-39 -5.4 (-8.3, -2.5)
#> 10 age effect 40-44 -5.5 (-8.5, -2.6)
#> 11 age effect 45-49 -5.4 (-8.6, -2.6)
#> 12 age effect 50-54 -5.4 (-8.7, -2.6)
#> 13 age effect 55-59 -5.4 (-8.7, -2.3)
#> 14 age hyper sd 0.96 (0.29, 2.9)
#> 15 disp disp disp 1.3 (0.45, 4.3)