Skip to contents

Calculates the standardized mean difference between two groups using the smd package. This is a common measure of effect size for comparing group differences while accounting for variability.

Usage

bal_smd(
  covariate,
  group,
  weights = NULL,
  reference_group = NULL,
  na.rm = FALSE
)

Arguments

covariate

A numeric vector containing the covariate values to compare.

group

A vector (factor or numeric) indicating group membership. Must have exactly two unique levels.

weights

An optional numeric vector of case weights. If provided, must have the same length as other input vectors. All weights must be non-negative.

reference_group

The reference group level for comparisons. Can be either a group level value or a numeric index. If NULL (default), uses the first level.

na.rm

A logical value indicating whether to remove missing values before computation. If FALSE (default), missing values in the input will produce NA in the output.

Value

A numeric value representing the standardized mean difference. Positive values indicate the comparison group has a higher mean than the reference group.

Details

The standardized mean difference (SMD) is calculated as: $$SMD = \frac{\bar{x}_1 - \bar{x}_0}{\sqrt{(s_1^2 + s_0^2)/2}}$$ where \(\bar{x}_1\) and \(\bar{x}_0\) are the means of the treatment and control groups, and \(s_1^2\) and \(s_0^2\) are their variances.

In causal inference, SMD values of 0.1 or smaller are often considered indicative of good balance between treatment groups.

See also

check_balance() for computing multiple balance metrics at once

Other balance functions: bal_corr(), bal_ks(), bal_vr(), check_auc(), check_balance()

Examples

bal_smd(nhefs_weights$age, nhefs_weights$qsmk)
#> [1] -0.2822208

# With weights
bal_smd(nhefs_weights$wt71, nhefs_weights$qsmk,
            weights = nhefs_weights$w_ate)
#> [1] 0.009030294