The smd package provides the smd method to compute standardized mean differences between two groups for continuous values (numeric and integer data types) and categorical values (factor, character, and logical). The method also works on matrix, list, and data.frame data types by applying smd() over the columns of the matrix or data.frame and each item of the list. The package is based on Yang and Dalton (2012).

The smd function computes the standardized mean difference for each level \(k\) of a grouping variable compared to a reference \(r\) level:

\[ d_k = \sqrt{(\bar{x}_r - \bar{x}_{k})^{\intercal}S_{rk}^{-1}(\bar{x}_r - \bar{x}_{k})} \]

where \(\bar{x}_{\cdot}\) and \(S_{rk}\) are the sample mean and covariances for reference group \(r\) and group \(k\), respectively. In the case that \(x\) is categorical, \(\bar{x}\) is the vector of proportions of each category level within a group, and \(S_{rk}\) is the multinomial covariance matrix.

Standard errors are computed using the formula described in Hedges and Olkin (1985):

\[ \sqrt{ \frac{n_r + n_k}{n_rn_k} + \frac{d_k^2}{2(n_r + n_k)} } \]





xi <- sample(1:20, 90, replace = TRUE)
smd(x = xi, g = gg2)
#>   term  estimate
#> 1    B 0.1687339


xc <- unlist(replicate(2, sort(sample(letters[1:3], 45, replace = TRUE)), simplify = FALSE))
smd(x = xc, g = gg2)
#>   term  estimate
#> 1    B 0.1946887



xl <- as.logical(rbinom(90, 1, prob = 0.5))
smd(x = xl, g = gg2)
#>   term estimate
#> 1    B        0

Other packages



Hedges, LV, and I Olkin. 1985. Statistical Methods for Meta-Analysis.

Yang, Dongsheng, and Jarrod E Dalton. 2012. “A Unified Approach to Measuring the Effect Size Between Two Groups Using SAS” 335: 1–6.