calc: conversions and confidence intervals¶
Approximate conversions between the statistics a meta-analyst meets in published papers: r, Cohen’s d, t, z, F, p-values, odds ratios and logit coefficients, and confidence intervals of correlations. Needs only numpy and scipy.
from apatools.calc import cohen_r_from_z, cohen_d_from_z, p_from_r, ci_from_r
z = -1.472
r = cohen_r_from_z(z) # r = -0.9 (short aliases: r_from_z, d_from_z, ...)
d = cohen_d_from_z(z) # d = -4.1
p = p_from_r(-0.79, 100) # p = 0.0
low, high = ci_from_r(0.45, 100, conf_level=0.95)
Design choices and caveats¶
All conversions are approximations. Most of them need an assumption that is rarely stated in the source paper; the docstring of each function names it.
nis the total sample size and the degrees of freedom of a t statistic aren - 2.Cohen’s d conversions assume two groups of equal size (
n_groups=2, with the number of groups as an argument where it makes sense). With unequal groups the result is biased; pass the group sizes to a dedicated meta-analysis tool instead.d_from_fis only meaningful for a two-group comparison (one numerator degree of freedom, whereF = t²).Two-tailed by default.
method="two-tailed"; any other string means one-tailed. The sign of an effect is lost when it is recovered from a p-value (r_from_p,d_from_p,ci_from_p): the result is|r|or|d|.zis a standard-normal deviate unless the name says “Fisher’s z” (z_from_r,r_from_z,unbiased_z).z_from_thas two interpretations that measure different things and are not interchangeable: withoutmethodit returns Fisher’s z of the corresponding correlation (sign kept); with amethodit returns the standard-normal deviate that has the same p-value as the t statistic (a normal approximation of the t distribution; always non-negative, the sign is lost).ci_from_ruses Fisher’s z transformation and so assumes bivariate normality; the interval is asymmetric aroundr.unbiased_zapplies the small-sample correction (Olkin and Pratt) and is recommended forn < 20.p_from_ciassumes a symmetric interval on the scale of the estimate; for ratios (OR, RR, HR) pass the log-transformed estimate and limits.logit_from_probituses the rule-of-thumb factor 1.7 (the theoretical ratio of the logistic and normal scales is about 1.81). The d ↔ log odds ratio conversions assume a logistic distribution of the underlying continuous variable (Hasselblad and Hedges, 1995; Chinn, 2000).conf_levelis the confidence level (0.95), in every function. Before version 0.2.0 some functions called italpha, and one of them meant a significance level by it; see the changelog.
Where it differs from R¶
There is no single R function to compare with: the conversions are textbook formulas (Cohen, 1988; Fritz et al.,
2012; Borenstein et al., 2009). Where R packages such as esc or compute.es give a conversion, expect agreement only
when the same assumptions (equal groups, the same degrees of freedom) are made.
Checked against¶
The formulas are covered by unit tests, including the property that conversions are inverses of each other where they
are defined (a round trip d → r → d returns d), which is the reason n_groups exists in all of them.
Literature¶
The references cited in the docstrings of the functions of this module (they are collected from the docstrings when the documentation is built; the software that does the work is on the software page).
Altman, D. G., & Bland, J. M. (2011). How to obtain the P value from a confidence interval. BMJ, 343, d2304. https://doi.org/10.1136/bmj.d2304
Borenstein, M., Hedges, L. V., Higgins, J. P. T., & Rothstein, H. R. (2009). Introduction to Meta-Analysis, ch. 7. Wiley. https://doi.org/10.1002/9780470743386
Chinn, S. (2000). A simple method for converting an odds ratio to effect size for use in meta-analysis. Statistics in Medicine, 19(22), 3127-3131. https://doi.org/10.1002/1097-0258(20001130)19:22<3127::aid-sim784>3.0.co;2-m
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates. (Reprinted 2013 by Routledge, https://doi.org/10.4324/9780203771587)
Fisher, R. A. (1921). On the “probable error” of a coefficient of correlation deduced from a small sample. Metron.
Fritz, C. O., Morris, P. E., & Richler, J. J. (2012). Effect size estimates: Current use, calculations, and interpretation. Journal of Experimental Psychology: General, 141(1), 2-18. https://doi.org/10.1037/a0024338
Hasselblad, V., & Hedges, L. V. (1995). Meta-analysis of screening and diagnostic tests. Psychological Bulletin, 117(1), 167-178. https://doi.org/10.1037//0033-2909.117.1.167
Hedges, L. V., & Olkin, I. (1985). Statistical Methods for Meta-Analysis. Academic Press.
Nakagawa, S., & Cuthill, I. C. (2007). Effect size, confidence interval and statistical significance: a practical guide for biologists. Biological Reviews, 82(4), 591-605. https://doi.org/10.1111/j.1469-185x.2007.00027.x
Olkin, I., & Pratt, J. W. (1958). Unbiased estimation of certain correlation coefficients. The Annals of Mathematical Statistics, 29(1), 201-211. https://doi.org/10.1214/aoms/1177706717