Search code examples
r

Hedges's g variance and standard error from Cohen's d in R


I need to calculate in R the variance and standard error based on the reported Cohen’s d value in a study. For instance, considering differences between two groups (n_group_1 = 25; n_group_2 = 25) that resulted in a Cohen’s d value of 0.58, I need three distinct values: (a) the value of Hedges' g; (b) the variance of Hedges' g; (c) and the standard error of Hedges' g. I appreciate your help!


Solution

  • Here are two functions to compute Hodges' g from Cohen's d. The functions' names could be improved upon.

    # Cohen's d to Hedges' g
    # Hedges' g computed from
    # Cohen's d and sample sizes
    d2g <- function(d, n1, n2 = n1) {
      n <- n1 + n2
      df <- n - 2L
      d/sqrt(n/df)
    }
    # Hedges' g standard error computed
    # from Cohen's d and sample sizes
    d2g_se <- function(d, n1, n2 = n1, var.equal = FALSE) {
      g <- d2g(d, n1, n2)
      if(var.equal) {
        sqrt(1/n1 + 1/n2)
      } else {
        sqrt( (n1 + n2)/(n1*n2) + g^2/(2*(n1 + n2)) )
      }
    }
    
    d2g(0.58, 25)
    #> [1] 0.5682816
    d2g(0.58, 25, 25)
    #> [1] 0.5682816
    d2g_se(0.58, 25, 25)
    #> [1] 0.2884951
    d2g_se(0.58, 25, 25, var.equal = TRUE)
    #> [1] 0.2828427
    

    Created on 2024-07-13 with reprex v2.1.0