Bootstrap¶
semiparametric_bootstrap()¶
Semiparametric bootstrap for parameter uncertainty.
Resamples death counts from their assumed distribution (Poisson or Binomial) conditional on the fitted expected deaths, then refits the model on each bootstrap sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
FitStMoMo
|
Fitted model to bootstrap. |
required |
nboot
|
int
|
Number of bootstrap replicates. |
500
|
seed
|
int | None
|
Random seed. |
None
|
n_jobs
|
int
|
Number of parallel jobs. Requires |
1
|
Returns:
| Type | Description |
|---|---|
BootStMoMo
|
|
Examples:
>>> from pystmomo import lc, load_ew_male, semiparametric_bootstrap
>>> data = load_ew_male()
>>> fit = lc().fit(data.deaths, data.exposures, ages=data.ages, years=data.years)
>>> boot = semiparametric_bootstrap(fit, nboot=100, seed=0)
>>> lo, hi = boot.parameter_ci("kt", level=0.95)
>>> lo.shape
(1, 51)
Source code in src/pystmomo/bootstrap/semipar_boot.py
residual_bootstrap()¶
Residual bootstrap for parameter uncertainty.
Resamples deviance residuals from the fitted model, converts them back to death counts, and refits the model on each bootstrap sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
FitStMoMo
|
Fitted model to bootstrap. |
required |
nboot
|
int
|
Number of bootstrap replicates. |
500
|
seed
|
int | None
|
Random seed. |
None
|
n_jobs
|
int
|
Number of parallel jobs (requires |
1
|
Returns:
| Type | Description |
|---|---|
BootStMoMo
|
|
Source code in src/pystmomo/bootstrap/residual_boot.py
BootStMoMo¶
Result of bootstrap uncertainty quantification.
Attributes:
| Name | Type | Description |
|---|---|---|
base_fit |
FitStMoMo
|
The original fitted model. |
nboot |
int
|
Number of bootstrap replicates. |
method |
Literal['semiparametric', 'residual']
|
Bootstrap method used: |
fits |
list[FitStMoMo]
|
List of refitted :class: |
ax_b |
ndarray | None
|
Bootstrap distribution of α_x, shape (nboot, n_ages) or None. |
bx_b |
ndarray
|
Bootstrap distribution of β_x, shape (nboot, n_ages, N). |
kt_b |
ndarray
|
Bootstrap distribution of κ_t, shape (nboot, N, n_years). |
b0x_b |
ndarray | None
|
Bootstrap distribution of β_x^(0), shape (nboot, n_ages) or None. |
gc_b |
ndarray | None
|
Bootstrap distribution of γ_c, shape (nboot, n_cohorts) or None. |
Source code in src/pystmomo/bootstrap/boot_result.py
ax_b
property
¶
Bootstrap ax, shape (nboot, n_ages).
b0x_b
property
¶
Bootstrap b0x, shape (nboot, n_ages) or None.
bx_b
property
¶
Bootstrap bx, shape (nboot, n_ages, N).
gc_b
property
¶
Bootstrap gc, shape (nboot, n_cohorts) or None.
kt_b
property
¶
Bootstrap kt, shape (nboot, N, n_years).
parameter_ci(param='kt', level=0.95)
¶
Bootstrap confidence interval for a parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
str
|
One of |
'kt'
|
level
|
float
|
Confidence level in (0, 1). |
0.95
|
Returns:
| Type | Description |
|---|---|
lower, upper:
|
Arrays of the same shape as the parameter, at the requested confidence level. |