
Publication-Ready Covariate Balance Table
balance_table.RdProduces a publication-ready covariate balance table comparing means, standard deviations, standardized mean differences (SMD), and variance ratios between treated and control groups. Optionally returns a gt or knitr formatted table.
Usage
balance_table(
data,
treatment,
covariates = NULL,
weights = NULL,
smd_threshold = 0.1,
digits = 3,
output_format = c("df", "kable", "gt"),
caption = "Covariate Balance Table"
)Arguments
- data
A data frame containing the covariates and treatment indicator.
- treatment
Character. Name of the binary treatment indicator column (0/1 or TRUE/FALSE).
- covariates
Character vector. Names of covariate columns to include. If
NULL(default), all numeric and logical columns excepttreatmentare used.- weights
Numeric vector of length
nrow(data). Optional analytical weights (e.g., inverse probability weights).- smd_threshold
Numeric. Threshold for flagging imbalanced covariates (|SMD| > threshold). Default
0.1.- digits
Integer. Number of decimal places. Default
3.- output_format
Character. Table format:
"df"(data frame, default),"kable"(knitr table), or"gt"(gt table).- caption
Character. Table caption for formatted outputs.
Value
A data frame (when output_format = "df") or formatted table
with columns:
- covariate
Covariate name.
- mean_control
Weighted mean in control group.
- mean_treated
Weighted mean in treated group.
- sd_control
Standard deviation in control group.
- sd_treated
Standard deviation in treated group.
- smd
Standardized mean difference.
- var_ratio
Variance ratio (treated/control).
- flag
Logical. Whether |SMD| exceeds
smd_threshold.
Details
The standardized mean difference (SMD) is computed as: $$SMD = \frac{\bar{X}_t - \bar{X}_c}{\sqrt{(s_t^2 + s_c^2)/2}}$$ following @rubin2001using. Values below 0.1 are conventionally considered well-balanced.
References
Rubin, D. B. (2001). Using propensity scores to help design observational studies: application to the tobacco litigation. Health Services and Outcomes Research Methodology, 2(3–4), 169–188.
Examples
data(lalonde, package = "MatchIt")
balance_table(
data = lalonde,
treatment = "treat",
covariates = c("age", "educ", "re74", "re75")
)
#> covariate mean_control mean_treated sd_control sd_treated smd var_ratio
#> 1 age 28.030 25.816 10.774 7.136 -0.242 0.439
#> 2 educ 10.235 10.346 2.852 2.005 0.045 0.494
#> 3 re74 5619.237 2095.574 6780.834 4873.395 -0.597 0.517
#> 4 re75 2466.484 1532.055 3288.157 3210.538 -0.288 0.953
#> flag
#> 1 TRUE
#> 2 FALSE
#> 3 TRUE
#> 4 TRUE