Skip to contents

[Stable]

Calculates standardized mean difference (SMD) effect sizes and their confidence intervals from raw data, with optional hypothesis testing.

Usage

smd_calc(
  x,
  ...,
  paired = FALSE,
  var.equal = FALSE,
  alpha = 0.05,
  bias_correction = TRUE,
  rm_correction = FALSE,
  glass = NULL,
  denom = c("auto", "z", "rm", "pooled", "avg", "glass1", "glass2"),
  smd_ci = c("nct", "goulet", "t", "z"),
  output = c("htest", "data.frame"),
  null.value = 0,
  alternative = c("none", "two.sided", "less", "greater", "equivalence",
    "minimal.effect"),
  test_method = c("z", "t"),
  tr = 0
)

# Default S3 method
smd_calc(
  x,
  y = NULL,
  paired = FALSE,
  var.equal = FALSE,
  alpha = 0.05,
  mu = 0,
  bias_correction = TRUE,
  rm_correction = FALSE,
  glass = NULL,
  denom = c("auto", "z", "rm", "pooled", "avg", "glass1", "glass2"),
  smd_ci = c("nct", "goulet", "t", "z"),
  output = c("htest", "data.frame"),
  null.value = 0,
  alternative = c("none", "two.sided", "less", "greater", "equivalence",
    "minimal.effect"),
  test_method = c("z", "t"),
  tr = 0,
  ...
)

# S3 method for class 'formula'
smd_calc(formula, data, subset, na.action, ...)

Arguments

x

a (non-empty) numeric vector of data values.

...

further arguments to be passed to or from methods.

paired

a logical indicating whether you want a paired t-test. Cannot be used with the formula method; use x and y vectors instead for paired tests.

var.equal

a logical variable indicating whether to treat the two variances as being equal. If TRUE then the pooled variance is used to estimate the variance otherwise the Welch (or Satterthwaite) approximation to the degrees of freedom is used.

alpha

alpha level (default = 0.05)

bias_correction

Apply Hedges' correction for bias (default is TRUE).

rm_correction

Repeated measures correction to make standardized mean difference Cohen's d(rm). This only applies to repeated/paired samples. Default is FALSE.

glass

An option to calculate Glass's delta as an alternative to Cohen's d type SMD. Default is NULL to not calculate Glass's delta, 'glass1' will use the first group's SD as the denominator whereas 'glass2' will use the 2nd group's SD.

denom

a character string specifying the denominator for standardization: - "auto": (default) Uses the standard denominator based on design and other arguments (glass, rm_correction, var.equal). - "z": SD of differences (Cohen's d_z). Valid for paired and one-sample designs. - "rm": Repeated-measures corrected (Cohen's d_rm). Valid for paired designs only. - "pooled": Pooled SD (Cohen's d_s). Valid for independent samples only. - "avg": Root-mean-square SD (Cohen's d_av). Valid for independent samples only. - "glass1": First group's (x) SD (Glass's delta). Valid for paired and independent designs. - "glass2": Second group's (y) SD (Glass's delta). Valid for paired and independent designs.

When set to any value other than "auto", this overrides the glass, rm_correction,
and var.equal arguments. The bias_correction argument is not affected.

smd_ci

Method for calculating SMD confidence intervals. Methods include 'goulet', 'noncentral t' (nct), 'central t' (t), and 'normal method' (z).

output

a character string specifying the output format: - "htest": (default) Returns an object of class "htest" compatible with standard R output. - "data.frame": Returns a data frame for backward compatibility.

null.value

a number or vector specifying the null hypothesis value(s) on the SMD scale: - For standard alternatives: a single value (default = 0) - For equivalence/minimal.effect: two values representing the lower and upper bounds

alternative

a character string specifying the alternative hypothesis: - "none": (default) No hypothesis test is performed; only effect size and CI are returned. - "two.sided": Test whether SMD differs from null.value - "less": Test whether SMD is less than null.value - "greater": Test whether SMD is greater than null.value - "equivalence": Test whether SMD is between specified bounds - "minimal.effect": Test whether SMD is outside specified bounds

test_method

a character string specifying the method for hypothesis testing: - "z": Use z-statistic (normal distribution) - "t": Use t-statistic with degrees of freedom from the SMD calculation

tr

a numeric value specifying the proportion of observations to trim from each tail when computing trimmed means and Winsorized variances (default = 0, no trimming). Must be in the range [0, 0.5). Common choices are 0.1 (10\ (20\ and the rescaled Winsorized standard deviation for the denominator, following Algina, Keselman, and Penfield (2005). The rescaling ensures the robust effect size equals Cohen's delta when data are normally distributed. Note: tr > 0 is not compatible with denom = "rm" or smd_ci = "goulet".

y

an optional (non-empty) numeric vector of data values.

mu

a number indicating the true value of the mean for the two-tailed test (or difference in means if you are performing a two sample test).

formula

a formula of the form lhs ~ rhs where lhs is a numeric variable giving the data values and rhs either 1 for a one-sample test or a factor with two levels giving the corresponding groups. For paired tests, use the default method with x and y vectors instead of the formula method.

data

an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula).

subset

an optional vector specifying a subset of observations to be used.

na.action

a function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action").

Value

If output = "htest" (default), returns a list with class "htest" containing:

  • estimate: The SMD estimate (Cohen's d, Hedges' g, or Glass's delta)

  • stderr: Standard error of the estimate

  • conf.int: Confidence interval with conf.level attribute

  • alternative: A character string describing the alternative hypothesis

  • method: A character string indicating what type of test was performed

  • data.name: A character string giving the name(s) of the data

  • statistic: Test statistic (only if alternative != "none")

  • parameter: Degrees of freedom (only if test_method = "t" and alternative != "none")

  • p.value: P-value for the test (only if alternative != "none")

  • null.value: The specified hypothesized value(s) (only if alternative != "none")

If output = "data.frame", returns a data frame containing:

  • estimate: The SMD estimate

  • SE: Standard error of the estimate

  • lower.ci: Lower bound of the confidence interval

  • upper.ci: Upper bound of the confidence interval

  • conf.level: Confidence level (1-alpha)

Details

This function calculates standardized mean differences (SMD) for various study designs:

  • One-sample design: Standardizes the difference between the sample mean and zero (or other specified value)

  • Two-sample independent design: Standardizes the difference between two group means

  • Paired samples design: Standardizes the mean difference between paired observations

The function supports multiple SMD variants:

  • Cohen's d: Classic standardized mean difference (bias_correction = FALSE)

  • Hedges' g: Bias-corrected version of Cohen's d (bias_correction = TRUE)

  • Glass's delta: Uses only one group's standard deviation as the denominator (glass = "glass1" or "glass2")

  • Repeated measures d: Accounts for correlation in paired designs (rm_correction = TRUE)

Different confidence interval calculation methods are available:

  • "nct": Uses the noncentral t-distribution (most accurate in most cases)

  • "goulet": Uses the Goulet-Pelletier method

  • "t": Uses the central t-distribution

  • "z": Uses the normal distribution

The denom parameter provides a direct way to select the standardization denominator. When denom is not "auto", it takes precedence over the glass, rm_correction, and var.equal arguments, which are overridden as needed. A message is emitted if any explicitly provided arguments are overridden. The bias_correction argument is always respected regardless of denom.

When tr > 0, the function computes a robust standardized mean difference using trimmed means and Winsorized variances. The trimmed mean removes a proportion tr of observations from each tail before computing the mean. The Winsorized variance replaces trimmed observations with the nearest remaining values before computing the variance. A rescaling constant ensures the robust effect size equals Cohen's delta under normality. This approach is recommended when distributions are heavy-tailed or contain outliers, as the robust effect size better reflects the separation between distributions than the standard Cohen's d (Algina et al., 2005).

For detailed information on calculation methods, see vignette("SMD_calcs").

Purpose

Use this function when:

  • You need to calculate standardized effect sizes (Cohen's d, Hedges' g, Glass's delta)

  • You want confidence intervals for your effect size estimates

  • You need effect sizes for meta-analysis or reporting

  • You want to compare effect sizes across different studies or measures

  • You want to test hypotheses about effect size magnitudes (e.g., equivalence testing)

References

Algina, J., Keselman, H. J., & Penfield, R. D. (2005). An alternative to Cohen's standardized mean difference effect size: A robust parameter and confidence interval in the two independent groups case. Psychological Methods, 10(3), 317-328.

Yuen, K. K., & Dixon, W. J. (1973). The approximate behaviour and performance of the two-sample trimmed t. Biometrika, 60(2), 369-374.

Examples

# Example 1: Independent groups comparison (Cohen's d)
set.seed(123)
group1 <- rnorm(30, mean = 100, sd = 15)
group2 <- rnorm(30, mean = 110, sd = 18)
smd_calc(x = group1, y = group2, bias_correction = FALSE)
#> 
#> 	Two Sample Standardized Mean Difference (SMD; Cohen's
#> 	d[av]=(x-y)/SD_avg)
#> 
#> data:  group1 and group2
#> 
#> alternative hypothesis: none
#> 95 percent confidence interval:
#>  -1.465782 -0.398128
#> sample estimates:
#> SMD (d[av]) 
#>  -0.9355902 
#> 

# Example 2: Independent groups with formula notation (Hedges' g)
df <- data.frame(
  value = c(group1, group2),
  group = factor(rep(c("A", "B"), each = 30))
)
smd_calc(formula = value ~ group, data = df)
#> 
#> 	Two Sample Standardized Mean Difference (SMD; Hedges's
#> 	g[av]=(A-B)/SD_avg)
#> 
#> data:  value by group
#> 
#> alternative hypothesis: none
#> 95 percent confidence interval:
#>  -1.4467236 -0.3929514
#> sample estimates:
#> SMD (g[av]) 
#>  -0.9234253 
#> 

# Example 3: Paired samples with repeated measures correction
before <- c(5.1, 4.8, 6.2, 5.7, 6.0, 5.5, 4.9, 5.8)
after <- c(5.6, 5.2, 6.7, 6.1, 6.5, 5.8, 5.3, 6.2)
smd_calc(x = before, y = after, paired = TRUE, rm_correction = TRUE)
#> 
#> 	Paired Sample Standardized Mean Difference (SMD; Hedges's
#> 	g[rm]=(x-y)/SD_rm)
#> 
#> data:  before and after
#> 
#> alternative hypothesis: none
#> 95 percent confidence interval:
#>  -1.34518816  0.06017759
#> sample estimates:
#> SMD (g[rm]) 
#>  -0.6600134 
#> 

# Example 4: Glass's delta (using only first group's SD)
smd_calc(x = group1, y = group2, glass = "glass1")
#> 
#> 	Two Sample Standardized Mean Difference (SMD; bias-corrected Glass's
#> 	g[x]=(x-y)/SD_x)
#> 
#> data:  group1 and group2
#> 
#> alternative hypothesis: none
#> 95 percent confidence interval:
#>  -1.4274782 -0.3877403
#> sample estimates:
#> SMD (g[x]) 
#> -0.9210091 
#> 

# Example 5: Two-sided test against null of 0
smd_calc(x = group1, y = group2,
         alternative = "two.sided", null.value = 0)
#> 
#> 	Two Sample Standardized Mean Difference (SMD; Hedges's
#> 	g[av]=(x-y)/SD_avg)
#> 
#> data:  group1 and group2
#> z = -3.3426, p-value = 0.00083
#> alternative hypothesis: true SMD is not equal to 0
#> 95 percent confidence interval:
#>  -1.4467236 -0.3929514
#> sample estimates:
#> SMD (g[av]) 
#>  -0.9234253 
#> 

# Example 6: Equivalence test (TOST)
smd_calc(x = group1, y = group2,
         alternative = "equivalence", null.value = c(-0.5, 0.5))
#> 
#> 	Two Sample Standardized Mean Difference (SMD; Hedges's
#> 	g[av]=(x-y)/SD_avg)
#> 
#> data:  group1 and group2
#> z = -1.5327, p-value = 0.9373
#> alternative hypothesis: equivalence
#> null values:
#> lower bound upper bound 
#>        -0.5         0.5 
#> 90 percent confidence interval:
#>  -1.3618604 -0.4775065
#> sample estimates:
#> SMD (g[av]) 
#>  -0.9234253 
#> 

# Example 7: Using t-distribution for test
smd_calc(x = group1, y = group2,
         alternative = "two.sided", null.value = 0,
         test_method = "t", smd_ci = "t")
#> 
#> 	Two Sample Standardized Mean Difference (SMD; Hedges's
#> 	g[av]=(x-y)/SD_avg)
#> 
#> data:  group1 and group2
#> t = -3.3426, df = 57.974, p-value = 0.001458
#> alternative hypothesis: true SMD is not equal to 0
#> 95 percent confidence interval:
#>  -1.4764260 -0.3704246
#> sample estimates:
#> SMD (g[av]) 
#>  -0.9234253 
#> 

# Example 8: Direct denominator selection
smd_calc(x = group1, y = group2, denom = "pooled")
#> 
#> 	Two Sample Standardized Mean Difference (SMD; Hedges's
#> 	g[s]=(x-y)/SD_pooled)
#> 
#> data:  group1 and group2
#> 
#> alternative hypothesis: none
#> 95 percent confidence interval:
#>  -1.4467217 -0.3929673
#> sample estimates:
#> SMD (g[s]) 
#> -0.9234308 
#> 
smd_calc(x = group1, y = group2, denom = "avg")
#> 
#> 	Two Sample Standardized Mean Difference (SMD; Hedges's
#> 	g[av]=(x-y)/SD_avg)
#> 
#> data:  group1 and group2
#> 
#> alternative hypothesis: none
#> 95 percent confidence interval:
#>  -1.4467236 -0.3929514
#> sample estimates:
#> SMD (g[av]) 
#>  -0.9234253 
#> 
smd_calc(x = before, y = after, paired = TRUE, denom = "rm")
#> 
#> 	Paired Sample Standardized Mean Difference (SMD; Hedges's
#> 	g[rm]=(x-y)/SD_rm)
#> 
#> data:  before and after
#> 
#> alternative hypothesis: none
#> 95 percent confidence interval:
#>  -1.34518816  0.06017759
#> sample estimates:
#> SMD (g[rm]) 
#>  -0.6600134 
#> 
smd_calc(x = group1, y = group2, denom = "glass1", bias_correction = TRUE)
#> 
#> 	Two Sample Standardized Mean Difference (SMD; bias-corrected Glass's
#> 	g[x]=(x-y)/SD_x)
#> 
#> data:  group1 and group2
#> 
#> alternative hypothesis: none
#> 95 percent confidence interval:
#>  -1.4274782 -0.3877403
#> sample estimates:
#> SMD (g[x]) 
#> -0.9210091 
#> 

# Example 9: Legacy data.frame output
smd_calc(x = group1, y = group2, output = "data.frame")
#>                  estimate        SE  lower.ci   upper.ci conf.level
#> Hedges's g(av) -0.9234253 0.2762605 -1.446724 -0.3929514       0.95