Calculate Balance Score
calculate_balance_score.Rd
This function calculates a covariate balance score by calculating (by default) the harmonic mean of the p-values from individual covariate balance tests. This does not require the assumptions that the covariates are independent.
Arguments
- p_values
A numeric vector containing p-values from individual covariate balance tests. All values must be between 0 and 1.
- na.rm
Logical; if TRUE (default), NA values are removed before calculation. If FALSE and NA values are present, the function will return NA.
- balance_metric
A character string specifying the metric to use for calculating the balance score. Valid options are "harmonic_mean" (default) and "product".
Value
A numeric value representing the overall balance score. Higher values indicate better covariate balance.
Examples
# Example with well-balanced covariates
p_vals <- c(0.8, 0.9, 0.85)
calculate_balance_score(p_vals)
#> [1] 0.848037
# Example with poorly balanced covariates
p_vals <- c(0.01, 0.02, 0.03)
calculate_balance_score(p_vals)
#> [1] 0.01636364
# Handling NA values
p_vals_with_na <- c(0.8, NA, 0.85)
calculate_balance_score(p_vals_with_na, na.rm = TRUE)
#> [1] 0.8242424