
In-Engine Propensity Score and Inverse Probability of Treatment Weighting (IPTW) Module
Source:R/propensity.R
generate_propensity_weights.RdComputes logistic regression propensity scores, Inverse Probability of Treatment Weighting (IPTW: ATE, ATT/SMR, stabilized weights), and pre/post Standardized Mean Difference (SMD) covariate balance diagnostics for comparative effectiveness studies.
Usage
generate_propensity_weights(
con = NULL,
cohort_table = "cohort",
target_id = 1L,
comparator_id = 2L,
covariate_cols = NULL,
treatment_col = "cohort_definition_id",
trim = 0.01
)Arguments
- con
Active DBI/DuckDB connection (required if
cohort_tableis a character table name).- cohort_table
Character table name or
data.framecontaining cohort subjects and covariates.- target_id
Integer identifier representing target (treated) cohort (
Z = 1, default 1L).- comparator_id
Integer identifier representing comparator cohort (
Z = 0, default 2L).- covariate_cols
Optional character vector of covariate column names to balance. If
NULL, auto-detects all numeric columns excluding cohort identifiers.- treatment_col
Column containing group indicators (default
"cohort_definition_id").- trim
Optional clipping threshold for extreme propensity scores (default
0.01).
Value
An object of class c("omop_propensity_result", "list") containing:
- data
data.framewith added columnspropensity_score,iptw_ate,iptw_att, andiptw_stabilized_ate.- balance
data.frameof pre- and post-weighting SMDs and means for each covariate.- coefficients
Named numeric vector of logistic regression coefficients.
- max_post_smd
Numeric maximum post-weighting ATE SMD across all evaluated covariates.