Learn R Programming

bage (version 0.9.4)

set_seeds: Reset Random Seeds in Model Object

Description

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.

Usage

set_seeds(mod, new_seeds = NULL)

Value

A modified version of mod.

Arguments

mod

An object of class "bage_mod", created with mod_pois(), mod_binom(), or mod_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() calls set_seeds() internally.)

  • mod_pois(), mod_binom(), mod_norm() Specify a model

  • fit() Fit a model

  • unfit() Reset model, deleting estimates

Examples

Run this code
## fit model
mod <- mod_pois(injuries ~ age,
                data = nzl_injuries,
                exposure = popn) |>
  fit()

## call 'components()'
components(mod)

## call 'components()' again - same results
components(mod)

## reset seeds
mod <- set_seeds(mod)

## calling 'set_seeds' unfits the model
is_fitted(mod)

## so we fit it again
mod <- fit(mod)

## when we call components, we get
## different results from earlier
components(mod)

Run the code above in your browser using DataLab