components.bage_mod {bage} | R Documentation |
Extract Values for Hyper-Parameters
Description
Extract values for hyper-parameters from a model object. Hyper-parameters include
main effects and interactions,
dispersion,
trends, seasonal effects, errors,
SVD, spline, and covariate coefficients,
standard deviations, correlation coefficients.
Usage
## S3 method for class 'bage_mod'
components(object, quiet = FALSE, original_scale = FALSE, ...)
Arguments
object |
Object of class |
quiet |
Whether to suppress messages.
Default is |
original_scale |
Whether values for
|
... |
Unused. Included for generic consistency only. |
Value
A tibble with four columns columns:
The return value contains the following columns:
-
term
Model term that the hyper-parameter belongs to. -
component
Component within term. -
level
Element within component . -
.fitted
An rvec containing draws from the posterior distribution.
Fitted vs unfitted models
components()
is typically called on a fitted
model. In this case, the values returned are
draws from the joint posterior distribution for the
hyper-parameters in the model.
components()
can, however, be called on an
unfitted model. In this case, the values returned
are draws from the joint prior distribution.
In other words, the values incorporate
model priors, and any exposure
, size
, or weights
argument, but not observed outcomes.
Scaling and Normal models
Internally, models created with mod_norm()
are fitted using transformed versions of the
outcome and weights variables. By default, when components()
is used with these models,
it returns values for .fitted
that are based on the transformed versions.
To instead obtain values for "effect"
, "trend"
, "season"
,
"error"
and "disp"
that are based on the
untransformed versions,
set original_scale
to TRUE
.
See Also
-
augment()
Extract values for rates, means, or probabilities, together with original data -
tidy()
Extract a one-line summary of a model -
mod_pois()
Specify a Poisson model -
mod_binom()
Specify a binomial model -
mod_norm()
Specify a normal model -
fit()
Fit a model -
is_fitted()
See if a model has been fitted -
unfit()
Reset a model
Examples
set.seed(0)
## specify model
mod <- mod_pois(injuries ~ age + sex + year,
data = nzl_injuries,
exposure = popn)
## extract prior distribution
## of hyper-parameters
mod |>
components()
## fit model
mod <- mod |>
fit()
## extract posterior distribution
## of hyper-parameters
mod |>
components()
## fit normal model
mod <- mod_norm(value ~ age * diag + year,
data = nld_expenditure,
weights = 1) |>
fit()
## dispersion (= standard deviation in normal model)
## on the transformed scale
mod |>
components() |>
subset(component == "disp")
## disperson on the original scale
mod |>
components(original_scale = TRUE) |>
subset(component == "disp")