Skip to content

Commit

Permalink
Merge pull request #21 from msrosenberg/dev-branch
Browse files Browse the repository at this point in the history
I2 confidence interval bug fix
  • Loading branch information
msrosenberg authored May 16, 2023
2 parents 2a16f74 + 187a3b5 commit a35ff68
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
28 changes: 14 additions & 14 deletions resources/metawin_help.html
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ <h3>Output</h3>
<pre><code>
Source I<sup>2</sup> 95% CI
-------------------------------------
Total 48.4444 34.9546 to 59.1366
Total 48.4444 17.9350 to 67.6113
</code></pre>
<p>
→ Citations: Higgins and Thompson (2002), Huedo-Medina <em>et al.</em> (2006)
Expand Down Expand Up @@ -1008,7 +1008,7 @@ <h3>Output</h3>
<p>Dixon, P.M. (1993) The bootstrap and the jackknife: Describing the precision of ecological indices. Pp. 290—318 in <em>Design and Analysis of Ecological Experiments</em>, S.M. Scheiner and J. Gurevitch, eds. Chapman and Hall, New York.</p>
<p>Hedges, L.V. and I. Olkin (1985) <em>Statistical Methods for Meta-analysis</em>. Academic Press, Orlando, FL.</p>
<p>Higgins, J.P.T. and S.G. Thompson (2002) Quantifying heterogeneity in a meta-analysis. <em>Statistics in Medicine</em> 21:1539–1558.</p>
<p>Huedo-Medina, T.B., F. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in meta-analysis: Q statistic or I2 index? <em>Psychological Methods</em> 11:193–206.</p>
<p>Huedo-Medina, T.B., J. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in meta-analysis: Q statistic or I2 index? <em>Psychological Methods</em> 11:193–206.</p>
<p>Orwin, R.G. (1983) A fail-safe N for effect size in meta-analysis. <em>Journal of Educational Statistics</em> 8(2):157–159.</p>
<p>Rosenberg, M.S. (2005) The file-drawer problem revisited: A general weighted method for calculating fail-safe numbers in meta-analysis. <em>Evolution</em> 59(2):464–468.</p>
<p>Rosenthal, R. (1979) The “file drawer problem” and tolerance for null results. <em>Psychological Bulletin</em> 86(3):638–641.</p>
Expand Down Expand Up @@ -1331,7 +1331,7 @@ <h3>Output</h3>
<pre><code>
Source I2 95% CI
-------------------------------------
Total 48.4444 34.9546 to 59.1366
Total 48.4444 17.9350 to 67.6113
</code></pre>
<p>
→ Citations: Higgins and Thompson (2002), Huedo-Medina <em>et al.</em> (2006)
Expand Down Expand Up @@ -1360,7 +1360,7 @@ <h3>Output</h3>
<p>Hedges, L.V. and I. Olkin (1985) <em>Statistical Methods for Meta-analysis</em>. Academic Press, Orlando, FL.</p>
<p>Higgins, J.P.T. and S.G. Thompson (2002) Quantifying heterogeneity in a meta-analysis. <em>Statistics in
Medicine</em> 21:1539–1558.</p>
<p>Huedo-Medina, T.B., F. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in
<p>Huedo-Medina, T.B., J. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in
meta-analysis: Q statistic or I2 index? <em>Psychological Methods</em> 11:193–206.</p>
</blockquote>

Expand Down Expand Up @@ -1652,8 +1652,8 @@ <h3>Output</h3>
<pre><code>
Source I2 95% CI
---------------------------------------------------
Heterocera (within) 57.8379 45.2319 to 67.5424
Rhopalocera (within) 3.0254 0.0000 to 16.5089
Heterocera (within) 57.8379 28.8567 to 75.0132
Rhopalocera (within) 3.0254 0.0000 to 28.1177
</code></pre>
<p>
→ Citations: Higgins and Thompson (2002), Huedo-Medina <em>et al.</em> (2006)
Expand Down Expand Up @@ -1693,7 +1693,7 @@ <h3>Output</h3>
<pre><code>
Source I2 95% CI
-------------------------------------
Total 48.4444 34.9546 to 59.1366
Total 48.4444 17.9350 to 67.6113
</code></pre>
<p>
→ Citations: Higgins and Thompson (2002), Huedo-Medina <em>et al.</em> (2006)
Expand Down Expand Up @@ -1722,7 +1722,7 @@ <h3>Output</h3>
<p>Hedges, L.V. and I. Olkin (1985) <em>Statistical Methods for Meta-analysis</em>. Academic Press, Orlando, FL.</p>
<p>Higgins, J.P.T. and S.G. Thompson (2002) Quantifying heterogeneity in a meta-analysis. <em>Statistics in
Medicine</em> 21:1539–1558.</p>
<p>Huedo-Medina, T.B., F. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in
<p>Huedo-Medina, T.B., J. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in
meta-analysis: Q statistic or I2 index? <em>Psychological Methods</em> 11:193–206.</p>
</blockquote>

Expand Down Expand Up @@ -1888,7 +1888,7 @@ <h3>Output</h3>
<pre><code>
Source I2 95% CI
-------------------------------------
Total 53.3385 40.5512 to 63.3753
Total 53.3385 24.2595 to 71.2532
</code></pre>
<p>
→ Citations: Higgins and Thompson (2002), Huedo-Medina <em>et al.</em> (2006)
Expand Down Expand Up @@ -1917,7 +1917,7 @@ <h3>Output</h3>
<p>Hedges, L.V. and I. Olkin (1985) <em>Statistical Methods for Meta-analysis</em>. Academic Press, Orlando, FL.</p>
<p>Higgins, J.P.T. and S.G. Thompson (2002) Quantifying heterogeneity in a meta-analysis.
<em>Statistics in Medicine</em> 21:1539–1558.</p>
<p>Huedo-Medina, T.B., F. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in
<p>Huedo-Medina, T.B., J. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in
meta-analysis: Q statistic or I2 index? <em>Psychological Methods</em> 11:193–206.</p>
<p>Rosenberg, M.S. (2013) Moment and least-squares based approaches to meta-analytic inference. Pp. 108–124 in
<em>Handbook of Meta-analysis in Ecology and Evolution</em>, J. Koricheva, J. Gurevitch and K.L. Mengersen, eds.
Expand Down Expand Up @@ -2091,7 +2091,7 @@ <h3>Output</h3>
<pre><code>
Source I2 95% CI
-------------------------------------
Total 54.3676 41.9334 to 64.1391
Total 54.3676 26.1112 to 71.8182
</code></pre>
<p>
→ Citations: Higgins and Thompson (2002), Huedo-Medina <em>et al.</em> (2006)
Expand Down Expand Up @@ -2121,7 +2121,7 @@ <h3>Output</h3>
<p>Hedges, L.V. and I. Olkin (1985) <em>Statistical Methods for Meta-analysis</em>. Academic Press, Orlando, FL.</p>
<p>Higgins, J.P.T. and S.G. Thompson (2002) Quantifying heterogeneity in a meta-analysis.
<em>Statistics in Medicine</em> 21:1539–1558.</p>
<p>Huedo-Medina, T.B., F. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in
<p>Huedo-Medina, T.B., J. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in
meta-analysis: Q statistic or I2 index? <em>Psychological Methods</em> 11:193–206.</p>
</blockquote>

Expand Down Expand Up @@ -2322,7 +2322,7 @@ <h3>Output</h3>
<pre><code>
Source I2 95% CI
-------------------------------------
Total 54.3676 41.9334 to 64.1391
Total 54.3676 26.1112 to 71.8182
</code></pre>
<p>
→ Citations: Higgins and Thompson (2002), Huedo-Medina <em>et al.</em> (2006)
Expand Down Expand Up @@ -2351,7 +2351,7 @@ <h3>Output</h3>
<p>Hedges, L.V. and I. Olkin (1985) <em>Statistical Methods for Meta-analysis</em>. Academic Press, Orlando, FL.</p>
<p>Higgins, J.P.T. and S.G. Thompson (2002) Quantifying heterogeneity in a meta-analysis. <em>Statistics in
Medicine</em> 21:1539–1558.</p>
<p>Huedo-Medina, T.B., F. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in
<p>Huedo-Medina, T.B., J. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) Assessing heterogeneity in
meta-analysis: Q statistic or I2 index? <em>Psychological Methods</em> 11:193–206.</p>
<p>Rosenberg, M.S., D.C. Adams, and J. Gurevitch (2000) <em>MetaWin: Statistical Software for Meta-analysis</em>.
Sinauer Associates, Sunderland, MA.</p>
Expand Down
14 changes: 7 additions & 7 deletions src/MetaWinAnalysisFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,16 @@ def bootstrap_means(bootstrap_n, boot_data, obs_mean, pooled_var, random_effects
def calc_i2(qt, n, alpha: float = 0.05):
try:
i2 = max(0, 100 * (qt - (n - 1))/qt)
ln_h2 = math.log(qt/(n - 1))
ln_h = math.log(math.sqrt(qt/(n - 1)))
if qt > n - 1:
se = (math.log(qt) - math.log(n-1))/(2*(math.sqrt(2*qt)-math.sqrt(2*n - 3)))
se_ln_h = (math.log(qt) - math.log(n-1))/(2*(math.sqrt(2*qt)-math.sqrt(2*n - 3)))
else:
se = math.sqrt((1/(2*(n - 2))) * (1 - (1/(3*(n - 2)**2))))
se_ln_h = math.sqrt((1/(2*(n - 2))) * (1 - (1/(3*(n - 2)**2))))
z = -scipy.stats.norm.ppf(alpha / 2)
lower_h2 = math.exp(ln_h2 - z*se)
upper_h2 = math.exp(ln_h2 + z*se)
lower_i2 = max(0, 100*(lower_h2 - 1)/lower_h2)
upper_i2 = max(0, 100*(upper_h2 - 1)/upper_h2)
lower_h = math.exp(ln_h - z*se_ln_h)
upper_h = math.exp(ln_h + z*se_ln_h)
lower_i2 = max(0, 100*(lower_h**2 - 1)/lower_h**2)
upper_i2 = max(0, 100*(upper_h**2 - 1)/upper_h**2)
except ZeroDivisionError:
i2, lower_i2, upper_i2 = 0, 0, 0
return i2, lower_i2, upper_i2
Expand Down
2 changes: 1 addition & 1 deletion src/MetaWinConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def resource_path(relative_path: str, inc_file: bool = False) -> str:
"Higgins_Thompson_2002": ["Higgins, J.P.T. and S.G. Thompson (2002) Quantifying heterogeneity in a meta-analysis. "
"<em>Statistics in Medicine</em> 21:1539&ndash;1558.", "Higgins and Thompson (2002)"],

"Huedo-Medina_et_2006": ["Huedo-Medina, T.B., F. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) "
"Huedo-Medina_et_2006": ["Huedo-Medina, T.B., J. Sánchez-Meca, F. Marín-Martínez, and J. Botella (2006) "
"Assessing heterogeneity in meta-analysis: Q statistic or I2 index? "
"<em>Psychological Methods</em> 11:193&ndash;206.", "Huedo-Medina <em>et al.</em> (2006)"],

Expand Down
7 changes: 7 additions & 0 deletions tests/borenstein_chap18.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
yi vi
0.09452 0.03295
0.27736 0.03070
0.36654 0.04988
0.66438 0.01051
0.46181 0.04266
0.18516 0.02342
13 changes: 13 additions & 0 deletions tests/test_metawin.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,19 @@ def test_simple_meta_analysis_lep():
assert round(analysis_values.i2, 2) == i2_answer


def test_i2_confidence_interval():
# not a formal test, just crosschecking values
data, _ = import_test_data("borenstein_chap18.txt")
options = MetaWinAnalysis.MetaAnalysisOptions()
options.structure = MetaWinAnalysis.SIMPLE_MA
options.effect_data = data.cols[0]
options.effect_vars = data.cols[1]
options.create_graph = False

output, figure, chart_data, analysis_values = MetaWinAnalysis.do_meta_analysis(data, options, 4)
print_test_output(output)


def test_simple_meta_analysis_lep_randeff():
# answers from Chapter 9, Handbook of Meta-Analysis in Ecology and Evolution
qt_answer = 23.01
Expand Down

0 comments on commit a35ff68

Please sign in to comment.