Diagnostics¶
Residuals¶
Signed sqrt of pointwise deviance contribution, shape (n_ages, n_years).
For Poisson (link='log'): - D > 0: sign(D - D̂) * sqrt(2(Dlog(D/D̂) - (D - D̂))) * sqrt(wxt) - D = 0: -sqrt(2 * D̂) * sqrt(wxt) [sign = -1, contribution = 2*D̂]
For Binomial (link='logit'): sign(D - Eq̂) * sqrt(2(Dlog(D/(Eq̂)) + (E-D)log((E-D)/(E(1-q̂))))) * sqrt(wxt)
Cells with wxt=0 are set to 0.
Note: wxt is binary 0/1, so sqrt(wxt) == wxt, but we use sqrt(wxt) so that squared residuals sum to the weighted deviance.
Source code in src/pystmomo/diagnostics/residuals.py
Pearson residuals, shape (n_ages, n_years).
For Poisson: (D - D̂) / sqrt(D̂) * sqrt(wxt) For Binomial: (D - Eq̂) / sqrt(Eq̂*(1-q̂)) * sqrt(wxt)
Cells with wxt=0 or zero variance are set to 0.
Source code in src/pystmomo/diagnostics/residuals.py
Cross-Validation¶
Period-based leave-last-out cross-validation.
Holds out the last n_test_years = n_years // n_folds consecutive years,
refits the model on the remaining years, forecasts h = n_test_years steps,
and compares predicted rates to observed rates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
FitStMoMo
|
A fitted FitStMoMo object. |
required |
n_folds
|
int
|
Number of folds. Determines the test window size as
|
5
|
metric
|
Literal['mse', 'log_mse']
|
Primary metric to return in 'metric_value': |
'mse'
|
Returns:
| Type | Description |
|---|---|
dict with keys:
|
|