Computes posterior predictive check (PPC) diagnostics for cohort-level
observed summaries against simulated summaries from a fitted lx_model.
The function supports:
cohorts = NULL: whole population (using respondents available for each selected component),a single
cohort,a
cohort_set.
Diagnostics are computed separately for each selected component (public,
private) and include predictive interval summaries, tail-based calibration,
bias summaries, and CRPS.
Usage
lx_ppc(
model,
cohorts = NULL,
components = c("public", "private"),
lower = 0.025,
upper = 0.975
)
# S3 method for class '`NULL`'
lx_ppc(
model,
cohorts = NULL,
components = c("public", "private"),
lower = 0.025,
upper = 0.975
)
# S3 method for class 'character'
lx_ppc(
model,
cohorts,
components = c("public", "private"),
lower = 0.025,
upper = 0.975
)
# S3 method for class 'cohort'
lx_ppc(
model,
cohorts,
components = c("public", "private"),
lower = 0.025,
upper = 0.975
)
# S3 method for class 'cohort_set'
lx_ppc(
model,
cohorts,
components = c("public", "private"),
lower = 0.025,
upper = 0.975
)Arguments
- model
An object of class
lx_model.- cohorts
A
cohort,cohort_set,NULL,"predictors"(all predictors + population),"population"(population-only), or a character vector of predictor names. Include"population"in an explicit vector when you also want the overall population cohort.- components
Character vector with any of
"public"and"private".- lower, upper
Numeric quantile probabilities for predictive and bias interval summaries. Defaults to
0.025and0.975.
Value
For a single
cohort: a tibble with one row per component and PPC metrics.For a
cohort_set: the input cohort set with an added list-columnppccontaining the per-cohort tibble.
Returned summaries also carry model metadata as attributes (for example,
experiment), mainly so lx_ppc_render() can use it for default sheet
naming.
Examples
if (FALSE) { # \dontrun{
model <- example_lx_model
# Whole population
lx_ppc(model)
# One cohort
cohort_female <- example_srv_lx |>
dplyr::filter(d_gender == "female") |>
g6tr.cohorts::create_cohort(id_col = response_id, weight_col = weight)
lx_ppc(model, cohorts = cohort_female)
} # }