Calculate the posterior distribution for a model.
Arguments
- object
A
bage_mod
object, created withmod_pois()
,mod_binom()
, ormod_norm()
.- method
Estimation method. Current choices are
"standard"
(the default) and"inner-outer"
. See below for details.- vars_inner
Names of variables to use for inner model when
method
is"inner-outer". If
NULL(the default)
vars_inner` is the age, sex/gender, and time variables.- ...
Not currently used.
Estimation methods
"standard"
All parameters, other than the lowest-level rates, probabilities, or means are jointly estimated within TMB. The default."inner-outer"
. Multiple-stage estimation, which can be faster than"standard"
for models with many parameters. In Step 1, the data is aggregated across all dimensions other than those specified invar_inner
, and a model for theinner
variables is fitted to the data. In Step 2, the data is aggregated across the remaining variables, and a model for theouter
variables is fitted to the data. Parameter estimtes from steps 1 and 2 are then combined.
See also
mod_pois()
,mod_binom()
,mod_norm()
Specify a modelaugment()
,components()
,tidy()
Examine output from a modelforecast()
Forecast, based on a modelreport_sim()
Simulation study of a modelunfit()
Reset a modelis_fitted()
Check if a model has been fitted
Examples
## specify model
mod <- mod_pois(injuries ~ age + sex + year,
data = injuries,
exposure = popn)
## examine unfitted model
mod
#> -- Unfitted Poisson model --
#>
#> injuries ~ age + sex + year
#>
#> (Intercept) ~ NFix()
#> age ~ RW()
#> sex ~ NFix()
#> year ~ RW()
#>
#> term n_par n_par_free
#> age 12 12
#> sex 2 2
#> year 19 19
#>
#> dispersion: mean=1
#> exposure: popn
#> var_age: age
#> var_sexgender: sex
#> var_time: year
#> n_draw: 1000
## fit model
mod <- fit(mod)
## examine fitted model
mod
#> -- Fitted Poisson model --
#>
#> injuries ~ age + sex + year
#>
#> (Intercept) ~ NFix()
#> age ~ RW()
#> sex ~ NFix()
#> year ~ RW()
#>
#> term n_par n_par_free std_dev
#> age 12 12 0.760
#> sex 2 2 0.720
#> year 19 19 0.081
#>
#> dispersion: mean=1
#> exposure: popn
#> var_age: age
#> var_sexgender: sex
#> var_time: year
#> n_draw: 1000
## extract rates
aug <- augment(mod)
aug
#> # A tibble: 912 × 9
#> age sex ethnicity year injuries popn .observed
#> <fct> <chr> <chr> <int> <int> <int> <dbl>
#> 1 0-4 Female Maori 2000 12 35830 0.000335
#> 2 5-9 Female Maori 2000 6 35120 0.000171
#> 3 10-14 Female Maori 2000 3 32830 0.0000914
#> 4 15-19 Female Maori 2000 6 27130 0.000221
#> 5 20-24 Female Maori 2000 6 24380 0.000246
#> 6 25-29 Female Maori 2000 6 24160 0.000248
#> 7 30-34 Female Maori 2000 12 22560 0.000532
#> 8 35-39 Female Maori 2000 3 22230 0.000135
#> 9 40-44 Female Maori 2000 6 18130 0.000331
#> 10 45-49 Female Maori 2000 6 13770 0.000436
#> # ℹ 902 more rows
#> # ℹ 2 more variables: .fitted <rdbl<1000>>, .expected <rdbl<1000>>
## extract hyper-parameters
comp <- components(mod)
comp
#> # A tibble: 37 × 4
#> term component level .fitted
#> <chr> <chr> <chr> <rdbl<1000>>
#> 1 (Intercept) effect (Intercept) -2.5 (-4.1, -0.86)
#> 2 age effect 0-4 -0.43 (-0.52, -0.35)
#> 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.53, 0.64)
#> 7 age effect 25-29 0.43 (0.37, 0.49)
#> 8 age effect 30-34 0.33 (0.27, 0.4)
#> 9 age effect 35-39 0.34 (0.28, 0.4)
#> 10 age effect 40-44 0.33 (0.27, 0.39)
#> # ℹ 27 more rows