The Canadian Postsecondary Education Alcohol and Drug Use Survey
(CPADS) is a Health Canada survey whose public-use microdata file (PUMF)
is open data. rmorie provides a canonical column contract and
morie_canonicalize_cpads_data(), which maps the raw PUMF
columns to analysis-ready names.
The examples use the synthetic CPADS frame that ships with rmorie: it has the PUMF’s columns but random values, so the numbers below are not findings about students. The real PUMF loads the same way (see “Loading the real PUMF”).
library(rmorie)
contract <- morie_cpads_contract()
contract$required_variables
#> [1] "weight" "alcohol_past12m" "heavy_drinking_30d"
#> [4] "ebac_tot" "ebac_legal" "cannabis_any_use"
#> [7] "age_group" "gender" "province_region"
#> [10] "mental_health" "physical_health"
unlist(contract$raw_column_map)
#> weight alcohol_past12m
#> "wtpumf" "alc05"
#> heavy_drinking_30d_total heavy_drinking_30d_fallback
#> "alc12_30d_prev_total" "alc12_30d_prev"
#> cannabis_any_use age_group
#> "can05" "age_groups"
#> gender province_region
#> "dvdemq01" "region"
#> mental_health physical_health
#> "hwbq02" "hwbq01"
#> ebac_tot ebac_legal
#> "ebac_tot" "ebac_legal"morie_cpads_contract() returns the canonical variable
names, the raw PUMF column each comes from, and notes on the source.
Using the contract is opt-in: the estimators in rmorie do not require
it.
raw <- morie_datasets_cpads(offline = TRUE)
#> morie_datasets_cpads(offline=TRUE): using the bundled synthetic cpads frame. This is a toy dataset with the documented schema but random data; do not interpret outputs as findings about the real population.
dim(raw)
#> [1] 500 394
df <- morie_canonicalize_cpads_data(raw)
# Returns the names of required canonical columns that are missing
# (character(0) when all are present); with strict = TRUE, the
# default, it stops instead.
morie_validate_cpads_data(df)
#> character(0)The PUMF weight is mapped to the canonical column
weight. A weighted proportion of heavy drinking in the past
30 days among respondents with a non-missing answer:
morie_run_propensity_ipw_analysis() estimates the effect
of a binary treatment on a binary outcome (by default
cannabis_any_use on heavy_drinking_30d) with a
logistic propensity model and trimmed inverse-probability weights. It
requires the weight column but does not apply the survey
weights in the estimate:
ipw <- morie_run_propensity_ipw_analysis(df)
ipw$ipw_results
#> estimand method estimate se ci_lower
#> 1 ATE IPW (trimmed) x survey weight -0.03048083 0.05044073 -0.1293447
#> ci_upper n y1_ipw y0_ipw
#> 1 0.068383 442 0.4969647 0.5274456
ipw$diagnostics
#> metric value
#> 1 ps_mean 0.4253394
#> 2 ps_min 0.3614675
#> 3 ps_max 0.5092979
#> 4 ipw_mean 2.0001035
#> 5 ipw_trimmed_mean 1.9996676
#> 6 ess_ipw_trimmed 430.7203920
#> 7 ess_survey_x_ipw_trimmed 389.0450856raw_real <- morie_load_dataset("ocp21")
df_real <- morie_canonicalize_cpads_data(raw_real)
dim(df_real)
# 40931 403This chunk is not run when the vignette is built, because the first call downloads the PUMF from open.canada.ca.
survey-weighted vignette covers stratified and
cluster sampling, design weights, design effects and bootstrap
variance.causal-inference vignette covers the ATE / ATT /
ATC / AIPW / CATE / GATE estimators.dataset-catalog vignette.