CPADS canonicalization and analysis

Overview

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”).

The CPADS column contract

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.

Loading and canonicalising

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)

Survey-weighted proportions

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:

ok <- !is.na(df$heavy_drinking_30d)
stats::weighted.mean(df$heavy_drinking_30d[ok], df$weight[ok])
#> [1] 0.5189609
mean(df$heavy_drinking_30d[ok])          # unweighted, for comparison
#> [1] 0.5098039

Propensity-score IPW workflow

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.0450856

Loading the real PUMF

raw_real <- morie_load_dataset("ocp21")
df_real  <- morie_canonicalize_cpads_data(raw_real)
dim(df_real)
# 40931   403

This chunk is not run when the vignette is built, because the first call downloads the PUMF from open.canada.ca.

Where to go next

  • The survey-weighted vignette covers stratified and cluster sampling, design weights, design effects and bootstrap variance.
  • The causal-inference vignette covers the ATE / ATT / ATC / AIPW / CATE / GATE estimators.
  • For Statistics Canada and Health Canada acknowledgment requirements, see the dataset-catalog vignette.