Data¶
StMoMoData¶
Container for mortality data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deaths
|
ndarray
|
Death counts matrix, shape (n_ages, n_years). |
required |
exposures
|
ndarray
|
Central or initial exposures matrix, shape (n_ages, n_years). |
required |
ages
|
ndarray
|
Age labels, length n_ages. |
required |
years
|
ndarray
|
Calendar year labels, length n_years. |
required |
type
|
Literal['central', 'initial']
|
|
'central'
|
series
|
str
|
Description of the population series, e.g. |
''
|
label
|
str
|
Short identifier for the dataset. |
''
|
Source code in src/pystmomo/data/_loader.py
central2initial()
¶
Convert central exposures to initial exposures.
Uses the approximation E_xt^0 ≈ E_xt^c + 0.5 * D_xt, which is
standard in the HMD methodology.
Returns:
| Type | Description |
|---|---|
StMoMoData
|
New object with |
Source code in src/pystmomo/data/_loader.py
subset(ages=None, years=None)
¶
Return a subset of the data restricted to given ages and/or years.
Source code in src/pystmomo/data/_loader.py
load_ew_male()¶
Load the bundled England & Wales male mortality dataset.
The dataset contains synthetic deaths and central exposures for English and Welsh males, ages 0–100, calendar years 1961–2011. It was generated to match published Human Mortality Database mortality patterns for illustrative purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ages
|
ndarray | list[int] | None
|
If provided, restrict to these ages. Defaults to ages 55–89, which are standard for CBD-family models. |
None
|
years
|
ndarray | list[int] | None
|
If provided, restrict to these calendar years. Defaults to all years (1961–2011). |
None
|
Returns:
| Type | Description |
|---|---|
StMoMoData
|
Central mortality data for the requested subset. |
Examples:
>>> import pystmomo as ps
>>> data = ps.load_ew_male()
>>> data.deaths.shape
(35, 51)
>>> data = ps.load_ew_male(ages=range(55, 90), years=range(1980, 2012))
Source code in src/pystmomo/data/_loader.py
load_hmd_csv()¶
Load mortality data from HMD-format CSV files.
HMD CSV files can be downloaded from https://www.mortality.org after
registration. The expected format has columns Year, Age, and
Total (or Male / Female).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deaths_file
|
str | Path
|
Path to the HMD deaths CSV (e.g., |
required |
exposures_file
|
str | Path
|
Path to the HMD exposures CSV (e.g., |
required |
series
|
str
|
Population series identifier ( |
''
|
label
|
str
|
Short dataset label. |
''
|
exposure_type
|
Literal['central', 'initial']
|
Whether the exposures file contains central ( |
'central'
|
Returns:
| Type | Description |
|---|---|
StMoMoData
|
|