View source: R/iptw_diagnostics.R
create_balance_plots | R Documentation |
Creates visualizations to assess covariate balance before and after IPTW weighting. Includes love plots (standardized differences) and propensity score distribution plots.
create_balance_plots(
iptw_result,
plot_type = "both",
threshold = 0.1,
save_plots = FALSE,
plot_dir = "plots"
)
iptw_result |
An iptw_result object from calc_iptw_weights() |
plot_type |
Type of plot: "love" for standardized differences, "ps" for propensity score distributions, or "both" |
threshold |
Threshold for acceptable standardized difference (default: 0.1) |
save_plots |
Whether to save plots to files (default: FALSE) |
plot_dir |
Directory to save plots if save_plots=TRUE (default: "plots") |
Shows standardized differences for each covariate before and after weighting. Points represent standardized differences, with lines connecting before/after values. Horizontal lines show common thresholds (0.1, 0.25) for acceptable balance.
Shows distributions of propensity scores by treatment group before and after weighting. Good overlap indicates positivity assumption is met.
A ggplot object (if plot_type is "love" or "ps") or a list of ggplot objects (if plot_type is "both"). If ggplot2 is not available, returns a message and creates base R plots.
data(cachar_sample)
# Calculate IPTW weights
iptw_result <- calc_iptw_weights(
data = cachar_sample,
treatment = "areca_nut",
covariates = c("age", "sex", "residence", "smoking")
)
# Create balance plots
if (requireNamespace("ggplot2", quietly = TRUE)) {
plots <- create_balance_plots(iptw_result, plot_type = "both")
print(plots$love_plot)
print(plots$ps_plot)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.