Skip to contents

Computes the Cohen's d and Hedges' g effect size statistics.

Usage

cohenD(
  x,
  y = NULL,
  conf.level = NA,
  sides = c("two.sided", "left", "right"),
  correct = FALSE,
  trim = 0,
  na.rm = FALSE,
  ...
)

Arguments

x

a non-empty numeric vector of data values

y

an optional non-empty numeric vector of data values

conf.level

confidence level of the interval. If set to NA (the default), only the point estimate is returned.

sides

character string specifying the sidedness of the confidence interval (one of "two.sided" (default), "left" or "right"). See ConfidenceIntervals().

correct

logical; whether to apply the Hedges correction. Defaults to FALSE.

trim

the fraction (0 to < 0.5) of observations trimmed from each end of each sample. 0 (default) gives Cohen's \(d\), values above 0 the robust effect size of Algina et al. (2005); see Details.

na.rm

logical. Should missing values be removed? Defaults to FALSE.

...

arguments for the bootstrap interval of the robust effect size (trim > 0), see Details. Not used otherwise.

Value

if conf.level = NA, a numeric scalar containing the effect size; otherwise a named numeric vector with elements:

est

point estimate of Cohen's \(d\) or Hedges' \(g\).

lci

lower confidence interval bound.

uci

upper confidence interval bound.

The magnitude category and pooled standard deviation are stored in the attributes magnitude and sdPooled, respectively. With trim > 0, sdPooled is the rescaled winsorized standard deviation \(s_{w,pooled} / c_\gamma\), i.e. the robust estimate of \(\sigma\).

Details

For a single sample, \(d = \bar{x} / s\); for two samples, \(d = (\bar{x} - \bar{y}) / s_{pooled}\). With correct = TRUE Hedges' bias correction \(J = 1 - 3/(4\nu - 1)\), with \(\nu\) the residual degrees of freedom, is applied to the estimate and, where computed, to the interval.

Confidence intervals invert the noncentral \(t\) distribution (Steiger & Fouladi): the noncentrality parameter is \(d\sqrt{n}\) with \(n - 1\) degrees of freedom in the one-sample case, and \(d / \sqrt{1/n_x + 1/n_y}\) with \(n_x + n_y - 2\) degrees of freedom in the two-sample case.

Robust version (trim > 0, Algina, Keselman & Penfield 2005). Means are replaced by trimmed means and standard deviations by winsorized ones, rescaled so that the result estimates Cohen's \(d\) under normality: $$d_R = c_\gamma\,\frac{\bar{x}_t - \bar{y}_t}{s_{w,pooled}},$$ where \(s_{w,pooled}\) pools the winsorized variances like the ordinary ones, and \(c_\gamma\) is the standard deviation of a standard normal variable winsorized at \(\gamma\) = trim (\(c_{0.2} = 0.642\)). In the one-sample case \(d_R = c_\gamma \bar{x}_t / s_w\). With normal data \(d_R\) and \(d\) agree; a few outliers, which inflate \(s\) and hence shrink \(d\), leave \(d_R\) largely untouched. trim = 0.2 is the usual choice. The noncentral-\(t\) interval does not apply here; the interval is a bootstrap interval (percentile by default, as recommended by Algina et al.; resampling within each sample). Arguments for the bootstrap are passed through ...: R (default 999), type ("perc", "basic", "norm" or "bca"), parallel and ncpus as in boot::boot(). The Hedges correction is not defined for \(d_R\), so correct = TRUE and trim > 0 cannot be combined.

sides names the side on which the finite bound lies: "left" yields \([lci, \infty)\), "right" yields \((-\infty, uci]\).

Note

Based on code by William Revelle.

References

Cohen, J. (1988) Statistical power analysis for the behavioral sciences (2nd ed.) Academic Press, New York.

Hedges, L. V. & Olkin, I. (1985) Statistical methods for meta-analysis Academic Press, Orlando, FL

Smithson, M.J. (2003) Confidence Intervals, Quantitative Applications in the Social Sciences Series, No. 140. Thousand Oaks, CA: Sage. pp. 39-41

Algina, J., Keselman, H. J. and 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, 317-328.

Examples


x <- Pizza$price[Pizza$driver == "Carter"]
y <- Pizza$price[Pizza$driver == "Miller"]

cohenD(x, y, conf.level = 0.95, na.rm = TRUE)
#>          est          lci          uci 
#> -0.212277884 -0.430316026  0.006058519 
#> attr(,"magnitude")
#> [1] "small"
#> attr(,"sdPooled")
#> [1] 21.54513

# Hedges' g
cohenD(x, y, conf.level = 0.95, correct = TRUE, na.rm = TRUE)
#>          est          lci          uci 
#> -0.211827825 -0.429403695  0.006045674 
#> attr(,"magnitude")
#> [1] "small"
#> attr(,"sdPooled")
#> [1] 21.54513

# one-sided: the finite bound lies on the left
cohenD(x, y, conf.level = 0.95, sides = "left", na.rm = TRUE)
#>        est        lci        uci 
#> -0.2122779 -0.3952370        Inf 
#> attr(,"magnitude")
#> [1] "small"
#> attr(,"sdPooled")
#> [1] 21.54513

# robust effect size of Algina, Keselman & Penfield
cohenD(x, y, trim = 0.2, na.rm = TRUE)
#> [1] -0.2142624
#> attr(,"magnitude")
#> [1] "small"
#> attr(,"sdPooled")
#> [1] 23.64795

# a single outlier shrinks d, but hardly d_R
set.seed(2)
a <- rnorm(25, mean = 1); b <- rnorm(25)
c(d = cohenD(a, b), dR = cohenD(a, b, trim = 0.2))
#>        d       dR 
#> 1.379422 1.469267 
a[25] <- 30
c(d = cohenD(a, b), dR = cohenD(a, b, trim = 0.2))
#>         d        dR 
#> 0.6402337 1.5347568 

set.seed(3)
cohenD(a, b, trim = 0.2, conf.level = 0.95, R = 499)
#>       est       lci       uci 
#> 1.5347568 0.8001885 2.4010677 
#> attr(,"magnitude")
#> [1] "large"
#> attr(,"sdPooled")
#> [1] 1.097514