# We try to balance the treatment variable in the cancer dataset based on age
# and sex covariates
data(cancer)
# Firstly, we define the formula
formula_cancer <- formula(status ~ age * sex)
# Then we can estimate the generalized propensity scores
gps_cancer <- estimate_gps(formula_cancer,
cancer,
method = "multinom",
reference = "control",
verbose_output = TRUE
)
# ... and drop observations based on the common support region...
csr_cancer <- csregion(gps_cancer)
# ... to match the samples using `match_gps()`
matched_cancer <- match_gps(csr_cancer,
reference = "control",
caliper = 1,
kmeans_cluster = 5,
kmeans_args = list(n.iter = 100),
verbose_output = TRUE
)
# At the end we can assess the quality of matching using `balqual()`
balqual(
matched_data = matched_cancer,
formula = formula_cancer,
type = "smd",
statistic = "max",
round = 3,
cutoffs = 0.2
)
Run the code above in your browser using DataLab