Models¶
Pre-built Models¶
Lee-Carter (LC) mortality model.
Linear predictor::
η_xt = α_x + β_x κ_t
Identifiability constraint: Σ_x β_x = 1, mean(κ_t) absorbed into α_x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link
|
Literal['log', 'logit']
|
|
'log'
|
Returns:
| Type | Description |
|---|---|
StMoMo
|
|
References
Lee, R.D. & Carter, L.R. (1992). Modeling and Forecasting U.S. Mortality. JASA, 87(419), 659–671.
Examples:
>>> from pystmomo import lc, load_ew_male
>>> model = lc()
>>> data = load_ew_male()
>>> fit = model.fit(data.deaths, data.exposures, ages=data.ages, years=data.years)
Source code in src/pystmomo/models/lc.py
Cairns-Blake-Dowd (CBD) mortality model.
Linear predictor::
η_xt = κ_t^(1) + (x - x̄) κ_t^(2)
No identifiability constraints are needed as the two period indexes are separately identified by the intercept and slope over age.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link
|
Literal['logit', 'log']
|
|
'logit'
|
Returns:
| Type | Description |
|---|---|
StMoMo
|
|
References
Cairns, A.J.G., Blake, D. & Dowd, K. (2006). A Two-Factor Model for Stochastic Mortality with Parameter Uncertainty. Journal of Risk and Insurance, 73(4), 687–718.
Examples:
>>> from pystmomo import cbd, load_ew_male
>>> data = load_ew_male()
>>> fit = cbd().fit(data.deaths, data.exposures, ages=data.ages, years=data.years)
Source code in src/pystmomo/models/cbd.py
Age-Period-Cohort (APC) mortality model.
Linear predictor::
η_xt = α_x + κ_t + γ_{t-x}
Identifiability constraints (following Villegas et al. 2018):
- Zero-mean period index: mean(κ_t) = 0, absorbed into α_x.
- Zero-mean cohort index: mean(γ_c) = 0.
- Zero linear trend in cohort index: no linear trend in γ_c.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link
|
Literal['log', 'logit']
|
|
'log'
|
Returns:
| Type | Description |
|---|---|
StMoMo
|
|
References
Currie, I.D. (2006). Smoothing and Forecasting Mortality Rates with P-splines. Talk at the Institute of Actuaries.
Examples:
>>> from pystmomo import apc, load_ew_male
>>> data = load_ew_male()
>>> fit = apc().fit(data.deaths, data.exposures, ages=data.ages, years=data.years)
Source code in src/pystmomo/models/apc.py
Renshaw-Haberman (RH) mortality model.
An extension of Lee-Carter with a cohort effect::
η_xt = α_x + β_x^(1) κ_t + β_x^(0) γ_{t-x}
where β_x^(0) is a freely-fitted cohort age modulation.
Identifiability constraints: LC sum constraint + zero-mean cohort effect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link
|
Literal['log', 'logit']
|
|
'log'
|
Returns:
| Type | Description |
|---|---|
StMoMo
|
|
References
Renshaw, A.E. & Haberman, S. (2006). A Cohort-Based Extension to the Lee-Carter Model for Mortality Reduction Factors. IME, 38(3), 556–570.
Examples:
>>> from pystmomo import rh, load_ew_male
>>> data = load_ew_male()
>>> fit = rh().fit(data.deaths, data.exposures, ages=data.ages, years=data.years)
Source code in src/pystmomo/models/rh.py
CBD model extended with a cohort effect (M6).
Linear predictor::
η_xt = κ_t^(1) + (x - x̄) κ_t^(2) + γ_{t-x}
Identifiability constraint: zero-mean cohort effect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link
|
Literal['logit', 'log']
|
|
'logit'
|
Returns:
| Type | Description |
|---|---|
StMoMo
|
|
References
Cairns, A.J.G., Blake, D., Dowd, K., Coughlan, G.D., Epstein, D., Ong, A. & Balevich, I. (2009). A Quantitative Comparison of Stochastic Mortality Models Using Data From England and Wales and the United States. NAAJ, 13(1), 1–35.
Examples:
>>> from pystmomo import m6, load_ew_male
>>> data = load_ew_male()
>>> fit = m6().fit(data.deaths, data.exposures, ages=data.ages, years=data.years)
Source code in src/pystmomo/models/m6.py
CBD model with quadratic age term and cohort effect (M7).
Linear predictor::
η_xt = κ_t^(1) + (x - x̄) κ_t^(2) + ((x - x̄)² - σ²_x) κ_t^(3) + γ_{t-x}
Three identifiability constraints are applied to the cohort effect: zero mean, zero linear trend, and zero quadratic trend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link
|
Literal['logit', 'log']
|
|
'logit'
|
Returns:
| Type | Description |
|---|---|
StMoMo
|
|
References
Cairns et al. (2009) — see :func:m6.
Examples:
>>> from pystmomo import m7, load_ew_male
>>> data = load_ew_male()
>>> fit = m7().fit(data.deaths, data.exposures, ages=data.ages, years=data.years)
Source code in src/pystmomo/models/m7.py
CBD model with age-modulated cohort effect (M8).
Linear predictor::
η_xt = κ_t^(1) + (x - x̄) κ_t^(2) + (x_c - x) γ_{t-x}
where x_c is a fixed reference age (typically ages[-1] + 0.5).
Identifiability constraint: zero-mean cohort effect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link
|
Literal['logit', 'log']
|
|
'logit'
|
xc
|
float | None
|
Reference age. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
StMoMo
|
|
References
Cairns et al. (2009) — see :func:m6.
Examples:
>>> from pystmomo import m8, load_ew_male
>>> data = load_ew_male()
>>> fit = m8(xc=float(data.ages[-1]) + 0.5).fit(
... data.deaths, data.exposures, ages=data.ages, years=data.years
... )
Source code in src/pystmomo/models/m8.py
Model Specification¶
Generalised Age-Period-Cohort (GAPC) stochastic mortality model.
The linear predictor is::
η_xt = α_x + Σ_i β_x^(i) κ_t^(i) + β_x^(0) γ_{t-x}
with death counts modelled as:
- Poisson (link =
"log"): D_xt ~ Poisson(E_xt · μ_xt) - Binomial (link =
"logit"): D_xt ~ Binomial(E_xt, q_xt)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link
|
Literal['log', 'logit']
|
Link function: |
required |
static_age_fun
|
bool
|
Whether to include a static age term α_x. |
required |
period_age_fun
|
tuple[AgeFunction, ...]
|
Tuple of age-modulating functions for period terms β_x^(i).
Use :class: |
()
|
cohort_age_fun
|
AgeFunction | None
|
Age-modulating function for the cohort term β_x^(0), or |
None
|
const_fun
|
Callable | None
|
Post-fit identifiability constraint function.
Signature: |
None
|
text_formula
|
str
|
Human-readable formula string for display. |
''
|
Examples:
Define the Lee-Carter model:
>>> from pystmomo import lc
>>> model = lc()
>>> print(model)
StMoMo(link='log', formula='η_xt = α_x + β_x κ_t')
Source code in src/pystmomo/core/stmomo.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
N
property
¶
Number of period terms (bilinear components).
has_cohort
property
¶
Whether the model includes a cohort effect.
is_fully_parametric
property
¶
True if all age functions are parametric (enabling GLM path).
fit(Dxt, Ext, ages, years, *, wxt=None, oxt=None, max_iter=500, tol=1e-06, verbose=False)
¶
Fit the model to mortality data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Dxt
|
ndarray
|
Deaths matrix, shape (n_ages, n_years). |
required |
Ext
|
ndarray
|
Exposures matrix (central or initial), shape (n_ages, n_years). |
required |
ages
|
ndarray
|
Age labels, length n_ages. |
required |
years
|
ndarray
|
Calendar year labels, length n_years. |
required |
wxt
|
ndarray | None
|
Optional binary weight matrix. Cells with weight 0 are excluded. Defaults to the automatic weight matrix that masks zero-exposure cells and sparse cohorts. |
None
|
oxt
|
ndarray | None
|
Log-exposure offset (log E_xt for Poisson; log E_xt for Binomial
initial exposures). If |
None
|
max_iter
|
int
|
Maximum IRLS iterations (bilinear path only). |
500
|
tol
|
float
|
Convergence tolerance on relative deviance change (bilinear path). |
1e-06
|
verbose
|
bool
|
Print iteration diagnostics (bilinear path only). |
False
|
Returns:
| Type | Description |
|---|---|
FitStMoMo
|
Fitted model result. |
Source code in src/pystmomo/core/stmomo.py
Age Functions¶
Age-modulating functions for GAPC mortality models.
Each function maps the age vector to a weight vector used in the linear predictor: η_xt = α_x + Σ_i f_i(x) κ_t^(i) + f_0(x) γ_{t-x}.
NonParametricAgeFun
¶
Sentinel that signals β_x must be fitted freely (Lee-Carter, RH).
When this appears in period_age_fun, the fitter switches to the
bilinear block-coordinate IRLS path.
Source code in src/pystmomo/core/age_functions.py
ConstantAgeFun
¶
Age function f(x) = 1 (constant).
Used in CBD: κ_t^(1) · 1.
Source code in src/pystmomo/core/age_functions.py
LinearAgeFun
¶
Age function f(x) = x - mean(ages).
Used in CBD: κ_t^(2) · (x - x̄).
Source code in src/pystmomo/core/age_functions.py
QuadraticAgeFun
¶
Age function f(x) = (x - x̄)² - σ²_x.
Centred quadratic used in M7.
Source code in src/pystmomo/core/age_functions.py
CenteredCohortAgeFun
¶
Age function f(x) = x_c - x for a fixed reference age x_c.
Used in M8: γ_{t-x} · (x_c - x).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xc
|
float
|
Reference age, typically the highest age in the data plus 0.5. |
89.5
|
Source code in src/pystmomo/core/age_functions.py
CallableAgeFun
¶
Wrap any callable f(ages) -> weights as a parametric age function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[ndarray], ndarray]
|
Callable that accepts a 1-D numpy array of ages and returns a 1-D array of weights of the same length. |
required |
name
|
str
|
Optional name for display. |
'custom'
|