Learn R Programming

bage

Fast Bayesian estimation and forecasting of age-specific rates.

Installation

install.packages("bage")

Example

Fit Poisson model to data on injuries

library(bage)
mod <- mod_pois(injuries ~ age:sex + ethnicity + year,
                data = nzl_injuries,
                exposure = popn) |>
  fit()
mod
#> 
#>     ------ Fitted Poisson model ------
#> 
#>    injuries ~ age:sex + ethnicity + year
#> 
#>                  exposure: popn
#> 
#>         term  prior along n_par n_par_free std_dev
#>  (Intercept) NFix()     -     1          1       -
#>    ethnicity NFix()     -     2          2    0.45
#>         year   RW()  year    19         19    0.09
#>      age:sex   RW()   age    24         24    0.88
#> 
#>  disp: mean = 1
#> 
#>  n_draw var_time var_age var_sexgender optimizer
#>    1000     year     age           sex    nlminb
#> 
#>  time_total time_max time_draw iter converged                    message
#>        0.52     0.08      0.09   13      TRUE   relative convergence (4)

Extract model-based and direct estimates

augment(mod)
#> # 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>>

Copy Link

Version

Install

install.packages('bage')

Monthly Downloads

198

Version

0.10.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

John Bryant

Last Published

November 19th, 2025

Functions in bage (0.10.2)

RW2_Seas

Second-Order Random Walk Prior with Seasonal Effect
RW2

Second-Order Random Walk Prior
N

Normal Prior
RW2_Infant

Second-Order Random Walk Prior with 'Infant' Indicator
RW_Seas

Random Walk Prior with Seasonal Effect
SVD

SVD-Based Prior for Age or Age-Sex Profiles
NFix

Normal Prior with Fixed Variance
Lin_AR1

Linear Prior with Autoregressive Errors of Order 1
RW

Random Walk Prior
SVD_AR

Dynamic SVD-Based Priors for Age Profiles or Age-Sex Profiles
WMD_C

Scaled SVD Components from World Marriage Database
Sp

P-Spline Prior
datamods

Data Models
augment.bage_mod

Extract Data and Modeled Values
components.bage_mod

Extract Values for Hyper-Parameters
data_wmd

Data to Create Scaled SVD Object Based on World Marriage Database
components.bage_ssvd

Extract Components used by SVD Summary
bage-package

Package 'bage'
generate.bage_ssvd

Generate Random Age or Age-Sex Profiles
dispersion

Extract Values for Dispersion
is_fitted

Test Whether a Model has Been Fitted
fit.bage_mod

Fit a Model
generate.bage_prior_ar

Generate Values from Priors
mod_binom

Specify a Binomial Model
forecast.bage_mod

Use a Model to Make a Forecast
datasets

Datasets
isl_deaths

Deaths in Iceland
computations

Information on Computations Performed During Model Fitting
kor_births

Births in South Korea
confidential

Confidentialization
mod_norm

Specify a Normal Model
prt_deaths

Deaths in Portugal
n_draw.bage_mod

Get the Number of Draws for a Model Object
mod_pois

Specify a Poisson Model
print.bage_mod

Printing a Model
nzl_divorces

Divorces in New Zealand
nzl_households

People in One-Person Households in New Zealand
nzl_injuries

Fatal Injuries in New Zealand
priors

Priors for Intercept, Main Effects, Interactions
nld_expenditure

Per Capita Health Expenditure in the Netherlands, 2003-2011
reexports

Objects exported from other packages
replicate_data

Create Replicate Data
report_sim

Simulation Study of a Model
set_datamod_exposure

Specify Exposure Data Model
set_covariates

Specify Covariates
set_datamod_overcount

Specify Overcount Data Model
set_confidential_rr3

Specify RR3 Confidentialization
set_datamod_outcome_rr3

Specify RR3 Data Model
set_prior

Specify Prior for Model Term
set_n_draw

Specify Number of Draws from Prior or Posterior Distribution
set_var_time

Specify Time Variable
ssvd

Create Object to Hold Data from a Scaled SVD
set_seeds

Reset Random Seeds in Model Object
set_var_sexgender

Specify Sex or Gender Variable
set_disp

Specify Prior for Dispersion or Standard Deviation
set_datamod_miscount

Specify Miscount Data Model
set_datamod_noise

Specify Noise Data Model
svds

Scaled SVDs
set_var_age

Specify Age Variable
swe_infant

Infant Mortality in Sweden
set_datamod_undercount

Specify Undercount Data Model
unfit

Unfit a Model
usa_deaths

Accidental Deaths in the USA
tidy.bage_mod

Summarize Terms from a Fitted Model
Lin_AR

Linear Prior with Autoregressive Errors
HIMD_R

Scaled SVD Components from Human Internal Migration Database
AR

Autoregressive Prior
Known

Known Prior
Lin

Linear Prior with Independent Normal Errors
AR1

Autoregressive Prior of Order 1
HMD

Scaled SVD Components from Human Mortality Database
HFD

Scaled SVD Components from Human Fertility Database
CSA

Scaled SVD Components from Census School Attendance Data
LFP

Scaled SVD Components from OECD Labor Force Participation Data