## Cohen's d

### Definition

It is used to estimate the population mean $$\mu$$

$d=\frac{\overline{X}_1 - \overline{X}_2}{S_p}$ where $$s$$ is the pooled standard deviation#

#### Example

x1 <- c(30.02, 29.99, 30.11, 29.97, 30.01, 29.99)
x2 <-c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)

sp_square <- ( (length(x1)-1) * sd(x1)^2 + (length(x2)-1) * sd(x2)^2 ) /(length(x1) + length(x2) -2)

d <- (mean(x1) - mean(x2)) / sqrt(sp_square)
d
##  1.131033
##### Using esc
library(esc)
esc_mean_sd(grp1m = mean(x1), grp1sd = sd(x1), grp1n = length(x1),
grp2m = mean(x2), grp2sd = sd(x2), grp2n = length(x2),
es.type = "d")
##
## Effect Size Calculation for Meta Analysis
##
##      Conversion: mean and sd to effect size d
##     Effect Size:   1.1310
##  Standard Error:   0.6218
##        Variance:   0.3866
##        Lower CI:  -0.0877
##        Upper CI:   2.3497
##          Weight:   2.5864
##### Using meta
library(meta)
## Loading 'meta' package (version 4.19-0).
## Type 'help(meta)' for a brief overview.
metacont(length(x1), mean(x1), sd(x1), length(x2), mean(x2), sd(x2),
sm = "SMD",
method.smd = "Cohen")
## Number of observations: o = 12
##
##     SMD            95%-CI    z p-value
##  1.1310 [-0.0877; 2.3497] 1.82  0.0689
##
## Details:
## - Inverse variance method
## - Cohen's d (standardised mean difference)

### Standard error

$SE(\hat{d}) = \sqrt{\frac{n_1+n_2}{n_1n_2}+\frac{\hat{d}^2}{2(n_1+n_2)}}$

#### Example

sqrt( (length(x1) + length(x2)) / (length(x1) * length(x2)) + d^2 / (2*(length(x1)+length(x2))) )
##  0.6217996

### Using esc

esc_mean_sd(grp1m = mean(x1), grp1sd = sd(x1), grp1n = length(x1),
grp2m = mean(x2), grp2sd = sd(x2), grp2n = length(x2),
es.type = "d")
##
## Effect Size Calculation for Meta Analysis
##
##      Conversion: mean and sd to effect size d
##     Effect Size:   1.1310
##  Standard Error:   0.6218
##        Variance:   0.3866
##        Lower CI:  -0.0877
##        Upper CI:   2.3497
##          Weight:   2.5864

## Hedges g

### Definition

Cohen's d is a biased estimator of the population effect size $$(\mu_1 - \mu_2) / \sigma$$

Hedges g is not biased

$g = J(n_1+n_2-2) d \approx \left( 1- \frac{3}{4 (n_1 +n_2) - 9}\right) d$

#### Example

d * (1- (3)/(4*(length(x1) +length(x2)) - 9))
##  1.04403
##### Using esc
esc_mean_sd(grp1m = mean(x1), grp1sd = sd(x1), grp1n = length(x1),
grp2m = mean(x2), grp2sd = sd(x2), grp2n = length(x2),
es.type = "g")
##
## Effect Size Calculation for Meta Analysis
##
##      Conversion: mean and sd to effect size Hedges' g
##     Effect Size:   1.0440
##  Standard Error:   0.6218
##        Variance:   0.3866
##        Lower CI:  -0.1747
##        Upper CI:   2.2627
##          Weight:   2.5864
##### Using meta
library(meta)
metacont(length(x1), mean(x1), sd(x1), length(x2), mean(x2), sd(x2), sm = "SMD")
## Number of observations: o = 12
##
##     SMD            95%-CI    z p-value
##  1.0440 [-0.1970; 2.2851] 1.65  0.0992
##
## Details:
## - Inverse variance method
## - Hedges' g (bias corrected standardised mean difference)