Extract values for hyper-parameters from a model object. Hyper-parameters include main effects and interactions, dispersion and variance terms, and SVD or spline coefficients.
Usage
# S3 method for class 'bage_mod'
components(
object,
standardize = c("terms", "anova", "none"),
quiet = FALSE,
...
)
Arguments
- object
Object of class
"bage_mod"
, typically created withmod_pois()
,mod_binom()
, ormod_norm()
.- standardize
Standardization method: one of
"terms"
,"anova"
, or "none". The default is"terms"
. See below for details.- quiet
Whether to suppress messages. Default is
FALSE
.- ...
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 modelled values 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 modelled values
are draws from the joint prior distribution.
In other words, the modelled values are informed by
model priors, and by any exposure
, size
, or weights
argument in the model, but not by the observed outcomes.
Standardizing estimates
Often the sum of the intercept, main effect, and interaction terms is well-identified by the data, but the values for individual terms is not. This indeterminancy does not affect the ultimate estimation of rates, probabilities, and means, but does complicate the interpretation of the higher-level terms.
One way of dealing with poorly-
identified terms is to post-process the estimates,
imposing some sort of standardization. There are
three options, specified through the standardize
argument:
"terms"
Each main effect or interaction, and any component terms such as trend or seasonal effects, are independently scaled so that they sum to 0."anova"
An ANOVA-style decomposition is carried out so that all variation associated with age is attributed to the age term, all variation associated with the interaction between age and sex is attributed to the age-sex term, and so on. Components terms such as trend and seasonal effects are left untouched."none"
No standardization is done.
"terms"
standardization is helpful for understanding
model dynamics. "anova"
standardization is helpful
for understanding the contribution of each variable
to overall patterns.
For a description of the standardization
algorithms used by bage,
see vignette("vig2_math")
.
See also
augment()
Extract data and values for rates, means, or probabilitiestidy()
Extract a one-line summary of a modelmod_pois()
Specify a Poisson modelmod_binom()
Specify a binomial modelmod_norm()
Specify a normal modelfit()
Fit a modelis_fitted()
See if a model has been fittedunfit()
Reset a model
Examples
## specify model
mod <- mod_pois(injuries ~ age + sex + year,
data = injuries,
exposure = popn)
## extract prior distribution
## of hyper-parameters
mod |>
components()
#> ℹ Model not fitted, so values drawn straight from prior distribution.
#> # A tibble: 37 × 4
#> term component level .fitted
#> <chr> <chr> <chr> <rdbl<1000>>
#> 1 (Intercept) effect (Intercept) -0.015 (-2, 1.8)
#> 2 age effect 0-4 -0.013 (-4.2, 4.4)
#> 3 age effect 5-9 -0.00086 (-3.6, 4)
#> 4 age effect 10-14 0.00028 (-3, 3.2)
#> 5 age effect 15-19 0.00058 (-2.2, 2.7)
#> 6 age effect 20-24 -0.00074 (-2, 2.7)
#> 7 age effect 25-29 0.0053 (-2.1, 2.2)
#> 8 age effect 30-34 0.00041 (-2.1, 2.2)
#> 9 age effect 35-39 0.016 (-2.2, 2.5)
#> 10 age effect 40-44 0.012 (-2.4, 2.7)
#> # ℹ 27 more rows
## fit model
mod <- mod |>
fit()
## extract posterior distribution
## of hyper-parameters
mod |>
components()
#> # A tibble: 37 × 4
#> term component level .fitted
#> <chr> <chr> <chr> <rdbl<1000>>
#> 1 (Intercept) effect (Intercept) -2.5 (-4.3, -0.86)
#> 2 age effect 0-4 -0.43 (-0.51, -0.36)
#> 3 age effect 5-9 -1.7 (-1.9, -1.6)
#> 4 age effect 10-14 -1.3 (-1.4, -1.2)
#> 5 age effect 15-19 0.44 (0.38, 0.5)
#> 6 age effect 20-24 0.59 (0.52, 0.64)
#> 7 age effect 25-29 0.43 (0.37, 0.49)
#> 8 age effect 30-34 0.34 (0.28, 0.4)
#> 9 age effect 35-39 0.34 (0.28, 0.4)
#> 10 age effect 40-44 0.33 (0.28, 0.39)
#> # ℹ 27 more rows