easystats / effectsize

:dragon: Compute and work with indices of effect size and standardized parameters
https://easystats.github.io/effectsize/
Other
331 stars 22 forks source link

Unbiased estimator of Glass' delta #625

Closed Daiki-Nakamura-git closed 5 months ago

Daiki-Nakamura-git commented 5 months ago

Hello, thank you for your continued development of the effectsize package. I would like to request that an unbiased estimator of Glass' delta be added to the effectsize package.

The estimator obtained by glass_delta() is not an unbiased estimator. The unbiased estimator is corrected by the correction factor J proposed by Hedges (1981).

Parameter $$\delta_g=\frac{\mu_E-\mu_C}{\sigma_C}$$ E: Experiment Group C: Control Group

Biased Estimator $$d_g=\frac{\bar{E}-\bar{C}}{\hat{\sigma_C}}$$

Unbiased Estimator $$\hat{\delta_g}=d_g*J$$ $$J=\frac{\Gamma{(df/2)}}{\sqrt{df/2}\cdot\Gamma{\frac{(df-1)}{2}}}$$ $$df=n_C-1$$

In R code, this can be expressed as follows.

# Data
ne <- 100 ; nc <- 100  # sample size
set.seed(123)  
E <- rnorm(ne, 2, 2)  # Experiment Group
C <- rnorm(nc, 1, 1)  # Control Group

# Biased Estimator
(dg <- (mean(E) - mean(C)) / sd(C))
library(effectsize)
effectsize::glass_delta(E, C) |> print(digits = 6) 

# Unbiased Estimator
df <- nc - 1  # degree of freedom
J <- gamma(df / 2) / (sqrt(df / 2) * gamma((df - 1) / 2)) # correction factor
(dg.adj <- dg * J)

Is there a function implemented to obtain such an unbiased estimator? If not, I would like to see it added.

mattansb commented 5 months ago

Weird, the code is internally in place, but wasn't available to the user. Is now on #626

# Data
ne <- 100 ; nc <- 100  # sample size
set.seed(123)  
E <- rnorm(ne, 2, 2)  # Experiment Group
C <- rnorm(nc, 1, 1)  # Control Group

# Biased Estimator
(dg <- (mean(E) - mean(C)) / sd(C))
#> [1] 1.332344
library(effectsize)
effectsize::glass_delta(E, C) |> print(digits = 6) 
#> Glass' delta |               95% CI
#> -----------------------------------
#> 1.332344     | [0.871576, 1.787429]

# Unbiased Estimator
df <- nc - 1  # degree of freedom
J <- gamma(df / 2) / (sqrt(df / 2) * gamma((df - 1) / 2)) # correction factor
(dg.adj <- dg * J)
#> [1] 1.32222

effectsize::glass_delta(E, C, adjust = TRUE) |> print(digits = 6) 
#> Glass' delta (adj.) |               95% CI
#> ------------------------------------------
#> 1.322220            | [0.864954, 1.773848]

Created on 2024-01-19 with reprex v2.0.2

Daiki-Nakamura-git commented 5 months ago

Thank you for the rapid correction.