Skip to content

Measures of effect size #5896

Open
Open

Description

@lewisdunne

When using statsmodels for hypothesis testing there are no effect sizes calculated/outputted. These are very important when it comes to communicating results because although a p value might be significant, the effect itself can still be tiny and practically meaningless.

It would be really good if measures of effect size could be included in the model summaries. I'm particularly thinking in terms of t-tests and ANOVAs. In the case of t-tests, the most frequently used is Cohen's d, while for ANOVA we have η^2, partial η^2, and ω^2.

Activity

  1. josef-pkt commented on Jun 29, 2019

    @josef-pkt
    Member

    Do you have a reference to other packages in how this works for example after OLS?

    I'm not sure how those are defined when we use a model and not a simple hypothesis test.

    (I'm going on vacation and might not be available for followup questions for a few days.)

  2. lewisdunne commented on Jun 29, 2019

    @lewisdunne
    Author

    There is a package called pingouin that implements effect sizes for its analyses. In OLS I'm not sure what the convention is in this regard. As I understand it the beta coefficients themselves are the effect sizes. As for pearson's r, again the r value itself is the effect size for example.

    Other than that, I can only point towards SPSS for reference, since this outputs estimates of effect size. R may also do this, but I don't have much experience with it. This page also has some useful information.

  3. josef-pkt commented on Jun 29, 2019

    @josef-pkt
    Member

    based on a quick look
    pingouin is GPL, so we are not allowed to use any of their code, but the documentation might be useful

    Ok, I think I misunderstood.
    This is for hypothesis tests and not directly for Models. So, this would be mainly an enhancement in the statsmodels.stats functions, and maybe to something like anova_lm

  4. lewisdunne commented on Jun 29, 2019

    @lewisdunne
    Author

    Ok, I think I misunderstood.
    This is for hypothesis tests and not directly for Models. So, this would be mainly an enhancement in the statsmodels.stats functions, and maybe to something like anova_lm

    Yes exactly, sorry I should have been clearer about that. And I think the most common situations in which effect sizes are needed will be all forms of ANOVA and t-tests.

  5. josef-pkt commented on Jun 29, 2019

    @josef-pkt
    Member

    AFAIK, all or most of these functions are very simple to code. The main work will be in writing unit tests against other packages and coming up with a useful API.

  6. josef-pkt commented on Jan 3, 2020

    @josef-pkt
    Member

    wikipedia has a good list
    https://en.wikipedia.org/wiki/Effect_size

    However, this authors have problems with finding good names for their x'th variant of an effect size.
    Basing an API on this names would just be a laundry list of functions that are not self explanatory and won't indicate what they are useful for.

    What would be useful is to have effect sizes for different hypothesis test and have the corresponding power/sample size functions available.

    for example from wikipedia
    cohen's q "is the difference between two Fisher transformed Pearson regression coefficients"
    i.e. we could use it for a z-test on equality of correlation coefficient.
    but I have no idea what "Pearson regression coefficients" is.

    similarly: we could add effect sizes that correspond to options in stats hypothesis tests and are based on the test statistic but doesn't include the effect of the sample size. This would at least apply to transformation based hypothesis tests using standard distributions.

  7. lewisdunne commented on Jan 3, 2020

    @lewisdunne
    Author

    I agree that having ES for different hypothesis tests makes the most sense since this is the context that they are used in.

    It would be really useful to have these as outputs when running any of the hypothesis tests, particularly for comparisons. So things like cohen's d for t-tests, and omega square & eta/partial eta square for ANOVA would be great as these are the standard measures.

  8. josef-pkt commented on Feb 6, 2020

    @josef-pkt
    Member

    another formula collection
    https://stats.idre.ucla.edu/other/mult-pkg/faq/general/effect-size-power/faqhow-is-effect-size-used-in-power-analysis/

    found while looking for ANOVA effect size used in power calculation #6496
    GPower manual describes the computation of effect sizes for their power/sample size functions
    (that's where I got the anova power design.)
    in several cases, GPower can compute effect sizes from different inputs, especially in regression/anova settings.

    related:

    naming conventions: use substantive names in keywords and function names, but add common names to the docstring to explain the options
    example anova for variance: Levene (anova on abs diff from mean), Brown-Forsythe (median as center), Welch (unequal variance), or rank based (?) or trimmed (Yuen)
    plus equivalence testing Welleck

    Levene_BrownForsythe_Welsh_Welleck_Anova = anova for variance with abs score, median center, unequal variance equivalence test
    :)
    Levy approximation of noncentrality parameter (nobs * effect size) for power of Welch anova

  9. josef-pkt commented on Feb 7, 2020

    @josef-pkt
    Member

    letter confusion

    "
    Notes:
    1 Beware the inconsistent terminology. What is labeled here as g was labeled by Hedges and Olkin as d and vice versa. For these authors writing in the early 1980s, g was the mainstream effect size index developed by Cohen and refined by Glass (hence g for Glass). Since then g has become synonymous with Hedges’ equation (not Glass’s) and the reason it’s called Hedges’ g and not Hedges’ h is because it was originally named after Glass – even though it was developed by Larry Hedges. Confused?
    "
    http://www.polyu.edu.hk/mm/effectsizefaqs/effect_size_equations2.html
    That's verbatim in a footnote in the book
    Ellis, Paul D. 2010. The Essential Guide to Effect Sizes: Statistical Power, Meta-Analysis, and the Interpretation of Research Results. Cambridge ; New York: Cambridge University Press.
    The book is not technical enough, not many formulas/equations,
    But, it has a laundry list of effect size measures and how to compute them in SPSS.

  10. josef-pkt commented on Feb 7, 2020

    @josef-pkt
    Member

    all-in-one effect size function

    escalc(measure, ai, bi, ci, di, n1i, n2i, x1i, x2i, t1i, t2i,
    m1i, m2i, sd1i, sd2i, xi, mi, ri, ti, sdi, r2i, ni, yi, vi, sei,
    data, slab, subset,
    add=1/2, to="only0", drop00=FALSE, vtype="LS",
    var.names=c("yi","vi"), add.measure=FALSE,
    append=TRUE, replace=TRUE, digits, ...)
    

    with a very long list of measures in the docstring and not using the typical one-letter names, e.g.

    • "MD" for the raw mean difference.
    • "SMD" for the standardized mean difference.
    • "SMDH" for the standardized mean difference with heteroscedastic population variances in
    the two groups (Bonett, 2008, 2009).
    • "ROM" for the log transformed ratio of means (Hedges et al., 1999; Lajeunesse, 2011)
    

    pakage metafor https://cran.r-project.org/web/packages/metafor/metafor.pdf
    examples in book "Applied Meta-Analysis with R" #1575 (comment)

  11. josef-pkt commented on Feb 7, 2020

    @josef-pkt
    Member

    @lewisdunne What additional properties of effect size measures do you need?

    I was working on the basic meta-analysis combining effect sizes across studies, and it looks like we need at least standard deviation for effect sizes and maybe more, e.g. confidence intervals if they are not just standard normal or t confidence intervals.

    I'm not sure what else.
    For nonlinear transformed effect sizes we need properties of the transformation (inverse transformation, maybe derivatives, ...)

    statsmodels internal use for effect sizes seems to be power/sample size functions and meta-analysis.

  12. lewisdunne commented on Feb 8, 2020

    @lewisdunne
    Author

    @lewisdunne What additional properties of effect size measures do you need?

    Thanks for working on this Josef, it is much appreciated! For my case it's totally adequate to have just the effect sizes themselves, and I am not very familiar with other cases so can't really comment on what else might be needed.

  13. josef-pkt commented on Mar 8, 2020

    @josef-pkt
    Member
  14. lcdunne commented on Mar 8, 2020

    @lcdunne

    I found an old mailing list thread again

    Yes this is actually me :) I could try to implement at least this change. I have never contributed to a project before and did not want to mess it up! I will go and watch some tutorials.

  15. josef-pkt commented on Mar 15, 2020

    @josef-pkt
    Member

    more variations on effect size: which one and for what purpose?

    Cumming, Geoff. 2013. “Cohen’s d Needs to Be Readily Interpretable: Comment on Shieh (2013).” Behavior Research Methods 45 (4): 968–71. https://doi.org/10.3758/s13428-013-0392-4.

    So far I can see 2 or 3 cases for different effect sizes

    • reporting a standard effect size as part of summary
    • effect size for use in meta-analysis
    • effect size for power and sample size computation for specific hypothesis tests and inference

    Cumming makes the point that what effect size we need for inference is in some cases not the one we need as standard measure (of for meta-analysis) that can be interpreted across studies.
    Their comment is to an article about Welch's t-test.
    The same applies for anova, where I have several different versions in the works #6526 #6496 #6444, specifically I need the effect size to get the non-centrality parameter for power and sample size computation in different versions of oneway anova. But these functions will need options to compute the "standard" effect size instead of or in addition to the inference effect size.

    #6444 (comment) psi f/omega/xi

  16. 3 remaining items

  17. lcdunne commented on Mar 24, 2020

    @lcdunne

    Hello once again. I finally managed to look more at this and have put together a very rough (for now) script. It contains some things that would be good additions I think, but it will need a lot more work. It is based on this paper and the example in the code matches the results that the author arrived at. Also I believe this was actually the author who drew attention to the difference between GPower & SPSS partial eta squared differences. He covers this in the paper so this is useful - the difference relates to a correction for within-subjects correlations in scores, for which SPSS corrects.

    As for the code itself, I think it would be great to somehow integrate these measures into the respective tests as results outputs, as you suggested. Maybe the results object could also contain an instance variable with each of the possible effect sizes?

    As for PRs, I still need to learn a bit! Thought this might at least be a start.

  18. josef-pkt commented on Mar 24, 2020

    @josef-pkt
    Member

    Thanks, @lcdunne

    A few days ago I ran into a blog post of Lakens showing that omega or epsilon are less biased than eta http://daniellakens.blogspot.com/2015/06/why-you-should-use-omega-squared.html
    although they have larger variance, and so mean squared error doesn't differ by as much.
    The followup article is

    Albers, Casper, and Daniël Lakens. 2018. “When Power Analyses Based on Pilot Data Are Biased: Inaccurate Effect Size Estimators and Follow-up Bias.” Journal of Experimental Social Psychology 74 (January): 187–95. https://doi.org/10.1016/j.jesp.2017.09.004.

    I don't know yet what I need for oneway anova. Currently I'm using eta and f to get the noncentrality for power analysis, and I have confidence intervals for those. (They are also used for oneway equivalence tests.) I haven't seen the use of omega or epsilon in the oneway anova literature yet.

    The plan is to return observed effect sizes (and maybe observed power) for the hypothesis tests, but also have standalone functions to compute it for prospective power analysis.

  19. josef-pkt commented on Mar 24, 2020

    @josef-pkt
    Member

    a few comments to your script

    For including the code in statsmodels we will need more informative names than a, b.

    If you have the reference numbers, then you can add them to the script and add assert_allclose. This helps you and us keeping track of what is already verified.
    e.g. my unit test were initially just some examples compared to the articles, and then included as unit tests
    783a3fc
    (I still need to rewrite my effectsize definitions in equivalence test, but I want to have unit tests so I avoid introducing refactoring mistakes.)

    It will be helpful if some of the functions take summary statistics so they can be reused by standalone functions and included in other functions or classes like hypothesis tests. (I wanted to add omega but didn't know how to compute it from the basic statistics of oneway anova.)
    This commit is the draft for the effect size in oneway anova that I'm working on
    07aac5b

    Aside: I'm not using sum of squares because I want to handle Welch anova and other cases where SS are usually not used.

  20. lcdunne commented on Mar 25, 2020

    @lcdunne

    Thanks for the feedback. I made a start on updating this with your suggestions, and will be referring to previous statsmodels code for formatting. Will make sure that summary stats can be used as alternative inputs wherever possible.

    I came up against the issue of how to structure the code given that many calculations are similar. That led me to this blog post where they discussed the many different ways to calculate Cohen's d, with some nice conclusions. So I will take some more time reading up and working on this.

    The R package effsize will probably be quite useful for setting this up.

  21. josef-pkt commented on Apr 7, 2020

    @josef-pkt
    Member

    to bias in eta and reduced bias in omega and epsilon:

    I haven't looked at it in a week or two, but NOT truncating negative (squared) effect sizes to zero still bothers me. I seems that the main reason that they don't do it , is so that they can show omega is less biased than eta. But that just includes "infeasible" values. A better measure would be to evaluate conditional on >0 or something like that, i.e. is it less biased if we get a positive effect size (e.g. positive eta).

    Albers and Lakens 2018 is much more a warning about not using small sample pilot studies at all, bias of effect size is less relevant and "confounded" by their truncation/selection bias, i.e. pilot study effect size has two consequences, sample size and not doing the study at all (as far as I could figure out). (i.e. their results only have the combined effect, or they are not explicit enough in this for me to infer the pure effectsize bias effect.)

  22. mario-bermonti commented on Jun 10, 2020

    @mario-bermonti

    I think this is a necessary addition for t-tests and ANOVAs. I usually end up using statsmodels for hypothesis testing and having to use pingouin for calculating effect sizes and then integrating them manually to the results.

    I mostly use Hedges’ G, which is a corrected version of the Cohen’s d and it is said to be an unbiased estimator of the effect size in the population.

    I mostly rely on the formulas of this paper. It contains the descriptions of different effect sized, formulas for calculating each one, for converting from one to the other, computing CIs for the effect size, and how to interpret them.

  23. josef-pkt commented on Jun 11, 2020

    @josef-pkt
    Member

    I'm still trying to figure out the different effect size measures and their uses, so feedback and review is useful. Also, if you have examples with the output that you expect and need, then this would be useful to check that we provide those.
    One problem that I still have is that I'm reading different strands of the literature that don't use consistent definitions or names, so I'm not always sure how things match up.

    Hedges' G is now in master as part of meta-analysis (standardized mean difference with unequal variance). I haven't yet looked in details for how to connect them to t-tests. It was written based on the standard meta-analysis literature.
    https://github.com/statsmodels/statsmodels/blob/master/statsmodels/stats/meta_analysis.py#L190

    I will merge oneway anova measures, #6789, soon, including eta2 and omega2 based on f-test/statistic. I haven't verified yet how they match up with measures defined in terms of sum of squares in the general anova_lm case.
    (I assume the definition of which partial eta-squared is captured by the f-test depends on the type of anova used in anova_lm.)

    I'm also trying to get confidence intervals for those effect measures.

    For example, for anova_lm (and general f_test), we can compute the effect size measures corresponding to the f-test.
    In my experimental code, not included in the oneway PR, I just create a DataFrame or add columns to the existing DataFrame based on the return of anova_lm. Would that be ok as user interface to have a function like this?

  24. mario-bermonti commented on Jun 16, 2020

    @mario-bermonti

    General

    Yeah. Reading this literature is kind of going down the rabbit hole. I usually use Hedge's G over plain Cohen's d in t-tests. But most of the literature uses Cohen's d (for some reason), and Hedge's is seen or used as optional. To be honest, I have never read a paper that presents Glass's effect size or r (correlation) for t-tests, so I would focus on Cohen's d and Hedge's g for t-tests and eta2 and omega2 for ANOVAs.

    Review

    • I would have organized all measures of effect sizes in a new module and then called them from the appropriate analysis. This way they would be easily accesible for all analyses that needed them (meta-analysis, t-test, ANOVA).

    • I would provide the user with the option of specifying if they want Cohen's d or Hedges. Again, I would always go with Hedges, but others might disagree.

    • Confidence intervals would be really great. Because we usually want to measure the uncertainty of the estimate.

    • I would include the effect size measure (and its confidence interval) as columns to the "results" dataframe as you suggest (its what I used to do manually)

    Output example

    Variable t p-value 95% CI Hedge's G
    cognitive process 1.46 0.15 0.39 [-2.25, 13.78]

    I'm happy to help, so ask away if anything comes up or you think I can help with anything else.

  25. josef-pkt commented on Jun 29, 2020

    @josef-pkt
    Member

    another confusion when we don't have the appropriate effect size functions

    https://stackoverflow.com/questions/62641730/why-sample-size-is-coming-as-double-with-statsmodels-package-in-python?noredirect=1#comment110780727_62641730

    which standard deviation is used in denominator of effect size for Cohen's d and TTestIndPower?
    (I did not remember it)

  26. LeanderK commented on Jul 13, 2020

    @LeanderK

    Hey, I am another user that desperately needs effect sizes. I would (right now) need partial eta squared to compare a restricted model to an unrestricted model. I think ideally computing it right at the f-test would be perfect!

    Regarding the different effect measures, i think that stats-models just need most of them.

  27. josef-pkt commented on Jul 17, 2020

    @josef-pkt
    Member

    It would be very helpful if any of you can provide test cases with the desired outcome.

    We have the effectsize for generic f-tests in regression, but I'm still not sure whether that's the expected outcome for a multi-way ANOVA.
    AFAIU, "partial" for generic f-tests depends on whatever was conditioned on when computing the f-test.

  28. albertbuchard commented on Oct 9, 2020

    @albertbuchard

    Here is a function that would be really useful to add to statsmodel (need to be adapted to more than one exogenous var)

    def anova_table(aov):
        aov['mean_sq'] = aov[:]['sum_sq']/aov[:]['df']
    
        aov['eta_sq'] = aov[:-1]['sum_sq']/sum(aov['sum_sq'])
    
        aov['omega_sq'] = (aov[:-1]['sum_sq']-(aov[:-1]['df']*aov['mean_sq'][-1]))/(sum(aov['sum_sq'])+aov['mean_sq'][-1])
    
        cols = ['sum_sq', 'df', 'mean_sq', 'F', 'PR(>F)', 'eta_sq', 'omega_sq']
        aov = aov[cols]
        return aov
    

    from https://www.pythonfordatascience.org/anova-python/#anova_statsmodels

  29. josef-pkt commented on Feb 5, 2023

    @josef-pkt
    Member

    not sure if this was already commented on or is available

    AFAICS, df_denom differs across types of anova, specifically sequential type 1 versus type 2 or 3.
    for power computation we need df_num AND df_denom for the rows of the anova table. We need to add df_denom if not yet available.
    see comments around #8403 (comment)

  30. joseluizn commented on Nov 15, 2025

    @joseluizn

    Was there ever any update on this? I was looking into ways to calculate effect size for ANOVA and only found an answer for one-way tests. Is there any partial eta squared implementation atm?

  31. josef-pkt commented on Nov 15, 2025

    @josef-pkt
    Member

    unfortunately nothing that is readily available.

    Whenever I look at this, I get confused by different definitions and don't see any theoretical background. Sum of squares are ambiguous in regression or multiway anova setting. (*)
    The sum of squares don't add up to total sum of squares in models, unless the data is a balanced anova (equal number of observations in every cell.) So, we get into the issue on what is the conditioning set of explanatory variables, type 1, 2 or 3 anova, which all give different answers.

    The google search AI gives a good answer to "statsmodels convert fstat to effect size" pointing out our helper function. It's generic but I added it when I worked on oneway models.
    The F-statistic is well defined and depends on the joint hypothesis that is tested. So, effect sizes derived from it reflect the same assumptions and conditioning sets as the corresponding F-test.

    There should be a recipe for computing eta and similar from the anova_lm table. But I'm not clear when we have total eta versus partial eta (I found several blog posts about the confusion between the different etas in what SPSS returns.)

    (*) related mess :)
    I was looking recently at measures of intra class correlations, ICC, in two way models (for interrater agreement).
    I gave up for now because there are too many different versions, and I did not spend enough time to get a good enough overview and understanding that made me want to implement any of those versions.
    In oneway models, the computation and interpretation of ICC is unambiguous, AFAIR.

    Aside:
    Penguin package implements more of those measures, but uses the basic formulas that have very restrictive assumptions.
    So far, I usually did not add those measures, when in many more general cases the underlying assumptions will not hold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions