Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calculating Hedge's g unbiased estimator manually

    Dear Statalist,

    I am using Stata v17.0 on a mac. I have a two independent group design with n1 = 206 and n2 = 276; df = 480.
    I am trying to calculate (replicate) Stata's 95%CIs for Hedge's g using the formula provided in the manual for esize. This involves caculating the unbiased estimator as follows:

    Click image for larger version

Name:	Hedges g estimator formula.png
Views:	1
Size:	23.2 KB
ID:	1680064

    I can replicate most of the cacluations. However, I have tried multiple times to replicate this unbiased estimator using the lngamma function in Stata. However, I do not come up with a plausable estimator value. Here is one of my attempts:
    Code:
    display (lngamma(480/2))/(ln(sqrt(480/2))*(lngamma(479/2)))
    I get a value of 0.36585431.

    I know this to be not plausible because applying Hedge's original approximation:
    Code:
    display 1-(3/(4*(206+276)-9))
    I get a value of 0.99843669.

    When I use this to calculate Hedge's g from Cohen's d, I get a similar result to Stata's esize command but not exact. When I use it to calculate 95%CIs, again I get a similar result but still not exact. I would really appreciate if someone with a more advanced statistical background could help me understand how Stata really calculates this unbiased estimator.
    Thanks for your consideration,
    Jesse.

  • #2
    The definition uses the gamma function twice, so that would be exp(lngamma()).

    More pedantically, the forms Hedges’ and Hedges’s both have supporters, but Hedge’s is wrong here.

    Comment


    • #3
      Thanks for the quick response Nick, much appreciated. However, this is where it gets more uncertain.

      If I use the gamma expression as you have suggested and replicate the statistical expression how it is written in the manual:
      Code:
      display exp(lngamma(480/2))/(sqrt(480/2)*(exp(lngamma(479/2))))
      .
      I do not get any results. In fact if I reduce it to the first term:
      Code:
      display exp(lngamma(480/2))
      .
      I do not get any results. I think this is because it is a very large number:
      Code:
      display lngamma(480/2)
      1073.5323
      This begs the question: If this is an incalculable number, how is Stata estimating this? Or am I missing something obvious?

      Also, thanks for the correction on Hedges' g - my apologies for the oversight.
      Last edited by Jesse Young; 31 Aug 2022, 03:31.

      Comment


      • #4
        Naturally I agree that the output of the gamma function explodes with even moderate input, which is precisely why the provision is of lngamma(). But the formula says what it says. Unfortunately I don't have any special expertise or experience with any of these measures. What's the source of the formulas you include as an image?

        Comment


        • #5
          This is a case when careful attention to transformation makes all the difference. Because of the nature of the gamma function, and the provision of the lngamma() function, you are best to express the adjustment factor, c(m), in terms of a log-transformation.

          Code:
          . di exp( lngamma(480/2) - lngamma(479/2) - ln(sqrt(480/2)) )
          
          .99843655
          The approximation noted above closely matches the equation given. What was failing your original attempt was not recognizing what happens to multiplication and division after taking the log of those operations.

          Comment


          • #6
            Nick: Thank you. The source of the image for the formulas is the Stata manual, esize section p.585.

            Leonardo: Thanks so much for this solution. When applied, it more closely approximates the solution provided by using the esize command to calculate Hedges' g with 95%CIs.

            For others' benefit, here is my calculations to replicate Hedges' g with 95%CIs manually.

            My sample has two independent groups with equal variances:
            Group 1: n1 = 206; mean1 = 1.082524; Std dev1 = 1.598165
            Group 2: n2 = 276; mean2 = 1.409420; Std dev2 = 1.779413

            Using the esize command, the estimate for Hedges' g = -0.1914994 (95%CI: -0.3719856, -0.0108147). This is what I aimed to replicate. Here is my code to do so:

            Aim 1: Calculate Hedges' g manually
            Step 1: Calculate mean difference for Cohen's d
            Code:
            di     1.082524-1.40942
            -.326896
            Mean difference = -0.326896

            Step 2: Calculate pooled standard deviation for Cohen's d
            Code:
            di sqrt(((206-1)*(1.598165^2)+((276-1)*(1.779413^2)))/(206+276-2))
            1.7043647
            Pooled SD = 1.7043647

            Step 3: Calculate Cohen's d
            Code:
            di -0.326896/1.7043647
            -.19179933
            Cohen's d = -0.19179933

            Step 4: Calculate Hedges' unbiased estimator correction
            Code:
            di exp( lngamma(480/2) - lngamma(479/2) - ln(sqrt(480/2)) )
            .99843655
            Unbiased estimator correction = 0.99843655

            Step 5: Calculate Hedges' g (Cohen's d * Hedges' unbiased estimator)
            Code:
            di -0.19179933*0.99843655
            -.19149946
            Hedges' g (manually calculated) = -0.19149946 vs. Hedges' g (from esize command) = -0.1914994

            Aim 2: Calculate 95%CI for Hedges' g manually

            Step 1: Calculate noncentrality parameter for two independent groups design
            Code:
            di (-0.19149946)*(sqrt((206*276)/(206+276)))
            -2.0798508
            Step 2: Find noncentrality parameters that correspond to upper and lower bounds
            Code:
            di npnt(480,-2.0798508,0.975) //calculate lower bound noncentrality parameter
            -4.043145
            di npnt(480,-2.0798508,0.025) //calculate upper bound noncentrality parameter
            -.11439989
            Lower bound noncentrality parameter = -4.043145
            Upper bound noncentrality parameter = -0.11439989

            Step 3: Transform the noncentrality parameters to the effect-size scale
            Code:
            di (-4.043145)*(sqrt((206+276)/(206*276))) // Lower 95%CI
            -.37226712
            di (-0.11439989)*(sqrt((206+276)/(206*276))) // Upper 95%CI
            -.01053322
            Unadj lower 95%CI: -0.37226712
            Unadj upper 95%CI: -0.01053322

            Step 4: Apply Hedges' unbiased estimator correction
            Code:
            di -0.37226712*0.99843655
            -.3716851
            di -0.01053322*0.99843655
            -.01051675
            Hedges' g 95%CI (manually calculated) = -0.3716851, -0.01051675 vs. Hedges' g 95%CI (from esize command) = -0.3719856, -0.0108147.
            Not quite exact but I suspect this is simply due to imprecise rounding when calculating it manually. Any further pointers or corrections for improvement are welcome. Special thanks to Nick and Leonardo for their guidance.
            Kind regards,
            Jesse.

            Comment

            Working...
            X