Plotting¶
Parameter Plots¶
Multi-panel plot of fitted model parameters.
Panels shown (only for non-None arrays): - α_x (ax) vs ages - β_x^(i) vs ages for each period term i - κ_t^(i) vs years for each period term i - β_x^(0) (b0x) vs ages (if present) - γ_c (gc) vs cohorts (if present)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
FitStMoMo
|
A fitted FitStMoMo object. |
required |
fig
|
Figure | None
|
Optional existing Figure to plot into. If None, a new Figure is created. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in src/pystmomo/plot/parameters.py
Forecast Fan Charts¶
Plot κ_t forecasts with confidence bands.
Expects fc to expose:
- fc.kt_central: shape (N, h) central forecast of period indexes
- fc.kt_lower: shape (N, h) lower confidence bound
- fc.kt_upper: shape (N, h) upper confidence bound
- fc.years: forecast year labels, length h
- fc.fit: original FitStMoMo (for historical kt and years)
Falls back gracefully if confidence bands are absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fc
|
A ForStMoMo forecast object. |
required | |
ages
|
list[int] | None
|
Ignored (present for API symmetry with rate-based plots). |
None
|
fig
|
Figure | None
|
Optional existing Figure; if None a new one is created. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in src/pystmomo/plot/forecast_plot.py
Fan chart of simulated mortality rates at a given age.
Expects sim to expose:
- sim.rates: shape (n_ages, h, nsim) array of simulated rates
- sim.ages: age labels, length n_ages
- sim.years: forecast year labels, length h
- sim.fit: original FitStMoMo (optional, for historical rates)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
A SimStMoMo simulation object. |
required | |
age
|
int
|
The age at which to draw the fan chart. |
required |
levels
|
tuple[float, ...]
|
Quantile coverage levels for fan bands (e.g. 0.95 → 2.5th–97.5th pct). |
(0.5, 0.8, 0.95)
|
fig
|
Figure | None
|
Optional existing Figure; if None a new one is created. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in src/pystmomo/plot/forecast_plot.py
Residual Plots¶
Heatmap of residuals on the ages × years grid.
Uses matplotlib imshow with the RdBu_r colormap, centred at zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
FitStMoMo
|
A fitted FitStMoMo object. |
required |
kind
|
str
|
Type of residuals: |
'deviance'
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in src/pystmomo/plot/residual_plot.py
Residuals vs fitted log-rates scatter plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
FitStMoMo
|
A fitted FitStMoMo object. |
required |
kind
|
str
|
Type of residuals: |
'deviance'
|
Returns:
| Type | Description |
|---|---|
Figure
|
|