| Title: | Tools for Self-Reported Health Indicators in Complex Surveys |
|---|---|
| Description: | Provides tools for analysing population health survey data (WHO STEPS, DHS, MICS, and similar complex sample surveys), where chronic conditions are self-reported rather than ICD-coded and estimates must account for stratification, clustering, and sampling weights. Includes a self-reported multimorbidity index based on the Functional Comorbidity Index (Groll et al., 2005, <doi:10.1016/j.jclinepi.2004.10.018>), design-weighted population prevalence estimation via the 'survey' package, a survey-weighted concentration index for health inequality analysis, a DHS anthropometric z-score categoriser, a choropleth mapping helper, and exploratory survey-weighted gradient boosting (via 'xgboost') with SHAP-based explainability. The gradient boosting component applies case weights but does not yet propagate cluster and strata design effects into variance estimates; it should be treated as exploratory rather than as design-based inference. |
| Authors: | Sujon Mia [aut, cre] |
| Maintainer: | Sujon Mia <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-16 21:42:31 UTC |
| Source: | https://github.com/stataid-research-lab/surveyncd |
Returns the standard condition list for the Functional Comorbidity Index.
fci_items()fci_items()
A character vector of the 18 FCI condition descriptions.
Groll, D. L., To, T., Bombardier, C., & Wright, J. G. (2005). The development of a comorbidity index with physical function as the outcome. Journal of Clinical Epidemiology, 58(6), 595-602. doi:10.1016/j.jclinepi.2004.10.018
Wraps the survey package to compute design-weighted multimorbidity
prevalence and mean condition count, properly accounting for the
stratification, clustering, and sampling weights of a complex survey
design (WHO STEPS, DHS, MICS, etc.). This is the step that turns an
individual-level score into a defensible population estimate – run
multimorbidity_index() first to create mm_category and
mm_n_conditions.
mm_prevalence(data, ids = NULL, strata = NULL, weights, by = NULL, nest = TRUE)mm_prevalence(data, ids = NULL, strata = NULL, weights, by = NULL, nest = TRUE)
data |
A data frame already processed by |
ids |
Name of the cluster/PSU column, or |
strata |
Name of the stratification column, or |
weights |
Name of the sampling weight column. |
by |
Optional single column name to compute subgroup estimates by
(e.g. |
nest |
Passed to |
A data frame with one row (or one row per by group),
containing n (unweighted sample size), prevalence /
prevalence_se / prevalence_lower / prevalence_upper (design-
weighted proportion "Multimorbid" with a logit-CI), and
mean_conditions / mean_conditions_se.
## Not run: scored <- multimorbidity_index(steps_data, conditions = c("htn", "dm")) mm_prevalence(scored, ids = "psu", strata = "region", weights = "wt") mm_prevalence(scored, ids = "psu", strata = "region", weights = "wt", by = "sex") ## End(Not run)## Not run: scored <- multimorbidity_index(steps_data, conditions = c("htn", "dm")) mm_prevalence(scored, ids = "psu", strata = "region", weights = "wt") mm_prevalence(scored, ids = "psu", strata = "region", weights = "wt", by = "sex") ## End(Not run)
Computes an individual-level multimorbidity score from a set of self-reported binary condition indicators (e.g. "Has a doctor ever told you that you have hypertension?"). This is designed for population health survey data (WHO STEPS, DHS, SAGE, etc.), where multimorbidity is captured through self-report rather than ICD-coded diagnoses – a data shape that existing comorbidity packages (which all assume ICD claims data) don't handle.
multimorbidity_index( data, conditions, weights = NULL, na_action = c("ignore", "na") )multimorbidity_index( data, conditions, weights = NULL, na_action = c("ignore", "na") )
data |
A data frame, one row per individual. |
conditions |
A character vector of column names in |
weights |
Optional named numeric vector giving a weight for each
condition (names must match |
na_action |
How to handle a row with at least one missing
condition. |
data with three columns appended: mm_n_conditions (raw
count of conditions present), mm_index (the possibly weighted
score), and mm_category (factor: "None", "Single condition",
"Multimorbid").
Groll, D. L., To, T., Bombardier, C., & Wright, J. G. (2005). The development of a comorbidity index with physical function as the outcome. Journal of Clinical Epidemiology, 58(6), 595-602. doi:10.1016/j.jclinepi.2004.10.018
df <- data.frame( id = 1:5, hypertension = c(1, 0, 1, 1, 0), diabetes = c(0, 0, 1, 1, 0), arthritis = c(1, 0, 0, 1, NA) ) multimorbidity_index(df, conditions = c("hypertension", "diabetes", "arthritis"))df <- data.frame( id = 1:5, hypertension = c(1, 0, 1, 1, 0), diabetes = c(0, 0, 1, 1, 0), arthritis = c(1, 0, 0, 1, NA) ) multimorbidity_index(df, conditions = c("hypertension", "diabetes", "arthritis"))
Generates a SHAP summary plot (similar to the Python shap package) where
features are ranked on the y-axis by their overall importance (mean absolute
SHAP value), SHAP values are shown on the x-axis, and each point (representing
a respondent) is colored by its relative value for that feature (blue for low,
red for high).
plot_shap_summary( shap_matrix, data, low_color = "#1e88e5", high_color = "#ff0052", title = "SHAP Summary Plot", subtitle = "Feature impact on model predictions (ranked by mean absolute SHAP)" )plot_shap_summary( shap_matrix, data, low_color = "#1e88e5", high_color = "#ff0052", title = "SHAP Summary Plot", subtitle = "Feature impact on model predictions (ranked by mean absolute SHAP)" )
shap_matrix |
The matrix output from |
data |
The matrix or data frame of training features (e.g. the |
low_color |
A character string for the color representing low feature values.
Default is |
high_color |
A character string for the color representing high feature values.
Default is |
title |
A character string for the plot title. Default is |
subtitle |
A character string for the plot subtitle. Default is
|
A ggplot2 object.
Converts alternative survey response values into clean standard numeric 0 or 1 scores.
recode_binary(x, yes, no = NULL)recode_binary(x, yes, no = NULL)
x |
A vector coding a single condition. |
yes |
The raw value(s) that should become 1. |
no |
The raw value(s) that should become 0. |
A numeric vector of 0, 1, or NA.
Computes the concentration index (the Wagstaff/O'Donnell "convenient covariance" formula) for a health outcome across a socioeconomic ranking variable, using proper survey sampling weights, and computes design-consistent standard errors, confidence intervals, and p-values.
survey_concentration_index(design, outcome, wealth, conf.level = 0.95)survey_concentration_index(design, outcome, wealth, conf.level = 0.95)
design |
A survey design object created by |
outcome |
Unquoted name of the health indicator (e.g. stunting_clean). |
wealth |
Unquoted name of the wealth/ranking variable (e.g. wealth_index). |
conf.level |
Confidence level for the confidence interval. Default is 0.95. |
where is the outcome for individual i, is the
weighted mean outcome, and is each individual's weighted
fractional rank in the wealth distribution.
The standard error, confidence intervals, and p-value are calculated using the
"convenient regression" method (Kakwani, Wagstaff, and van Doorslaer 1997)
run via survey::svyglm():
where is the weighted variance of the fractional rank. The
coefficient is mathematically identical to the concentration index,
and its standard error from the regression model is a design-consistent standard
error that fully accounts for stratification and clustering.
A tibble with Concentration_Index, Standard_Error,
Lower_CI, Upper_CI, p_value, Outcome_Mean,
and n.
This function merges calculated survey indicators with any provided spatial shapefile to generate a publication-ready thematic map.
survey_map_indicator( survey_data, shapefile, join_by, fill_var, palette = c("magma", "viridis", "plasma", "inferno", "cividis"), legend_title = NULL, border_color = "white", border_width = 0.2 )survey_map_indicator( survey_data, shapefile, join_by, fill_var, palette = c("magma", "viridis", "plasma", "inferno", "cividis"), legend_title = NULL, border_color = "white", border_width = 0.2 )
survey_data |
A data frame containing the aggregated survey indicators. |
shapefile |
An |
join_by |
A character string of the column name present in both datasets to merge on. |
fill_var |
A character string of the variable in |
palette |
A character string specifying the viridis color palette option to use:
|
legend_title |
A character string for the legend title. If |
border_color |
A character string for the region border line color. Default is |
border_width |
A numeric value for the border line width. Default is |
A ggplot2 spatial map object.
This function cracks open a trained survey-weighted XGBoost model and calculates the SHapley Additive exPlanations (SHAP values) for every respondent.
survey_shap(sxgb_model)survey_shap(sxgb_model)
sxgb_model |
The list output from the |
A matrix of SHAP values detailing the marginal contribution of each feature to the final prediction for every observation.
This function trains an Extreme Gradient Boosting (XGBoost) model while strictly enforcing sampling weights from a complex survey design object.
survey_xgboost(design, formula, params = list(), nrounds = 100)survey_xgboost(design, formula, params = list(), nrounds = 100)
design |
A |
formula |
A formula specifying the response and predictor variables. |
params |
A list of XGBoost parameters (e.g., objective, eta, max_depth). |
nrounds |
The number of boosting iterations. |
A list containing the trained xgb.Booster model and the xgb.DMatrix.
Cleans raw DHS/MICS z-score variables (e.g., hw70, hw71, hw72), adjusts the decimal scaling if needed, handles DHS-specific missing flags, applies WHO biologically implausible flagging rules, and categorizes them into WHO severity tiers.
who_anthro_score( x, indicator = c("stunting", "wasting", "underweight"), scaled_by_100 = TRUE, remove_implausible = TRUE )who_anthro_score( x, indicator = c("stunting", "wasting", "underweight"), scaled_by_100 = TRUE, remove_implausible = TRUE )
x |
A numeric vector of raw DHS/MICS z-scores. |
indicator |
The type of indicator for labeling and flagging: |
scaled_by_100 |
Logical. If |
remove_implausible |
Logical. If
|
A factor vector of WHO categories (Severe, Moderate, Normal) with the indicator label appended.