Skip to contents

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, quiet = FALSE, ...)

Arguments

object

Object of class "bage_mod", typically created with mod_pois(), mod_binom(), or mod_norm().

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.

See also

Examples

## specify model
mod <- mod_pois(injuries ~ age + sex + year,
                data = nzl_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 (0, 0)
#>  3 age         effect    5-9          -0.0094 (-2.2, 2.2)
#>  4 age         effect    10-14          -0.0077 (-3, 3.2)
#>  5 age         effect    15-19         -0.013 (-3.6, 4.1)
#>  6 age         effect    20-24       -0.00077 (-4.1, 4.6)
#>  7 age         effect    25-29         -0.00016 (-5, 5.5)
#>  8 age         effect    30-34         0.0022 (-5.6, 5.8)
#>  9 age         effect    35-39           0.01 (-5.7, 5.9)
#> 10 age         effect    40-44            0.017 (-6.1, 6)
#> # ℹ 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) -5.8 (-6.9, -4.7)
#>  2 age         effect    0-4                  0 (0, 0)
#>  3 age         effect    5-9         -1.3 (-1.5, -1.2)
#>  4 age         effect    10-14       -0.87 (-1, -0.73)
#>  5 age         effect    15-19       0.86 (0.76, 0.97)
#>  6 age         effect    20-24            1 (0.9, 1.1)
#>  7 age         effect    25-29       0.86 (0.75, 0.96)
#>  8 age         effect    30-34       0.76 (0.65, 0.86)
#>  9 age         effect    35-39       0.76 (0.66, 0.87)
#> 10 age         effect    40-44       0.75 (0.65, 0.87)
#> # ℹ 27 more rows