Skip to content

SUMM/REF/ENH: refactor, reorganize current proportions #6721

Open

Description

@josef-pkt

a reminder for now

Whenever I look for something in proportions.py, I'm getting a bit confused what cases the different functions include. I wrote it a long time ago mostly replicating individual functions in the documentation of other stats packages.

Similar to newer stats like two sample proportions, we should have basic functions with method options for 1-sample case, confint for 1sample proportion follows that pattern.

details:
stats.proportion.proportion_effectsize is the arcsine-sqrt version, now also in meta-analysis
it's for the 2 independent sample case, but that's not obvious from the name. It was written for power computation using arcsine and normal distribution.

Activity

  1. josef-pkt commented on May 16, 2020

    @josef-pkt
    MemberAuthor

    a missing piece ? #6720

    samplesize_confint_proportion currently implements only method="normal". I wrote it to get a quick approximate sample size, when sample sizes are pretty large.

    Needs binom "exact" as second method, or better
    add a power version that can be used to compute coverage. I think there is no explicit formula for binom based sample size, That will have the saw-tooth pattern and needs iteration.

  2. changed the title [-]SUMM/REF/ENH: reorganizing current proportions[/-] [+]SUMM/REF/ENH: refactor, reorganize current proportions[/+] on Apr 1, 2022
  3. josef-pkt commented on Apr 1, 2022

    @josef-pkt
    MemberAuthor

    another issue: equivalence tests

    • power_ztost_prop : uses z-test as hypothesis test, but has option to compute "exact" power using binom distribution
    • power_binom_tost: based on two one-sided binom hypothesis tests but only computes "normal power"
    • _power_ztost: helper function to compute normal power or exact binomial power

    It would be better to combine into one function with "method" options, test-method and power-method

    and reorganize tost functions
    binom_tost is for 1-sample and
    proportions_ztost might be for both 1 sample and 2indep diff, it delegates with 2 calls to proportions_ztest
    proportions_ztest combines 1 sample and 2 sample

  4. josef-pkt commented on Apr 25, 2022

    @josef-pkt
    MemberAuthor

    parking 2 references

    PASS documentation Chapter 110 Equivalence Tests for One Proportion
    includes normal power for wald, waldcc, score, scorecc, and maybe exact (? formula doesn't look like exact binom test)
    and binomial power for those

    https://www.ucl.ac.uk/english-usage/staff/sean/resources/confidence-intervals.pdf
    https://corplingstats.wordpress.com/2021/04/24/accurate-confidence-intervals/
    statistical linguistics
    with some extra statistics like mover difference of difference

  5. josef-pkt commented on Apr 26, 2022

    @josef-pkt
    MemberAuthor

    some one-sample modifications

    naming convention

    create new confint_proportion and we deprecate the old one
    I prefer now better method names, e.g.
    exact-c instead of beta, Clopper-Pearson
    exact_minlike ? for binomial, binom test (I don't yet use postfix minlike in poisson )
    midp-c and midp-minlike
    score instead of wilson
    wald instead of normal

    default
    and Wald should not be a default in any new functions, it's just bad when we have much better alternative

    extras

    • "m" "modified" bersions: boundary modification: ? add 0.5 or switch to different method, eg. exact or poisson (Brown et al 2001, section 4.1)
    • "cc" versions, e.g. in poisson I added cc and ccv

    We don't have midp yet, confint for midp will need to come from inversion of test function, possible discretness, non-monotonicity problems in computation (we had problems for inverting binom_test)

    we need "arcsin" as method, mainly as companion to proportion_effectsize (but that is for 2indep)

    test_proportion as companion to confint_proportions
    I didn't find a good overview and comparison article. I guess we use mainly the hypothesis test equivalent of the confint

    other functions

    • tost_proportion: with method option, just delegate to two tests
    • power_proportion: method and method_power option, currently method_power is mixed between normal and exact
      method might be restricted to only a few options, currently wald and binom
    • power_tost_proportion: ?
    • samplesize onetail, can delegate to generic
    • ...

    deprecations:

    most binom and proportion functions that implement a single method should be deprecated when we have the equivalent main function with the method option

    problems

    • proportions_ztest is multipurpose function combined for 1- and 2-sample cases, (in analogy to R)
      we need to check that the new functions cover all cases
    • vectorization: what are the implicit options in the current functions? most are vectorized, but proportion_ztest vectorized for 2 different cases.
      correction AFAICS, proportion_ztest is not vectorized, it has an explicit np.size check and raises if size is not 1 or 2.
      That has the advantage that we don't have backwards compatibility problems replicating some vectorization.

    update
    two more references I had downloaded and most likely used

    Newcombe, Robert G. 1998. “Two‐sided Confidence Intervals for the Single Proportion: Comparison of Seven Methods.” Statistics in Medicine 17 (8): 857–72. https://doi.org/10.1002/(SICI)1097-0258(19980430)17:8<857::AID-SIM777>3.0.CO;2-E.
    downloaded, added to zotero 2012

    Newcombe, Robert G. 2011. “Measures of Location for Confidence Intervals for Proportions.” Communications in Statistics - Theory and Methods 40 (10): 1743–67. https://doi.org/10.1080/03610921003646406.
    downloaded, added to zotero 2015

  6. josef-pkt commented on Apr 27, 2022

    @josef-pkt
    MemberAuthor

    another function: sample size to get specified length of confidence interval

    samplesize_confint_proportion current function with simple formula based on normal distribution, no reference in the docstring
    one unit test with a consistency check
    Note, there is no power argument. it is replace by the desired half length of the confint

    It looks like I just solved the definition of half-length for nobs.
    PASS has docs for it. Chapter 115 Confidence Intervals for One Proportion (my copy downloaded in 2015)
    PASS has it for all the standard one-proportion confint methods

    a reference, I briefly skimmed it, It has the standard confint methods

    Gonçalves, Luzia, M. Rosário de Oliveira, Cláudia Pascoal, and Ana Pires. 2012. “Sample Size for Estimating a Binomial Proportion: Comparison of Different Methods.” Journal of Applied Statistics 39 (11): 2453–73. https://doi.org/10.1080/02664763.2012.713919.

    (I'm skipping this for now.)

  7. josef-pkt commented on Apr 29, 2022

    @josef-pkt
    MemberAuthor

    computational aside for one-sample confint:
    Brown, Cai and Dasgupta 2001 have computation of midp confint using average of two Beta calls.
    I have not seen it anywhere else, even recent articles use iterative search when presenting midp.
    (In poisson I also invert the test for midp to get confint)

    if this works, then midp can be vectorized and is a very good default.
    Advantage of midp over score method is that it is more equal-tailed, score has a small bias in location relative to alpha / 2 rejection rate in each tail. So midp should also be more accurate for one-sided tests.

    I have not yet looked at the skew corrected score tests as Laud, or other higher order expansions and corrections (like cornish-fisher).

  8. added this to the 0.15 milestone on Nov 30, 2022
  9. josef-pkt commented on Feb 21, 2023

    @josef-pkt
    MemberAuthor

    r packages for confint_proportion

    https://www.rdocumentation.org/packages/prevalence/versions/0.4.0/topics/propCI
    this matches what we currently have

    these two have large overlap and additional confints, e.g. modified wilson and modified jeffreys
    https://rdrr.io/cran/MKmisc/man/binomCI.html
    https://rdrr.io/cran/DescTools/man/BinomCI.html

    The Wald with continuity correction interval is obtained by adding the term 1/(2*n) to the Wald interval.
    as in #3211 AFAICS

    I still need to check the references again for modified versions and continuity correction

    Aside: Jeffeys' at corner case count=0 or count=nobs, i.e. observed proportion is 0 or 1
    our Jeffreys' interval does not include 0 if count=0.
    R functions set the lower bound equal to 0 if count=0, i.e. modify the Jeffreys' method.

    current unit test have

        if (count == 0 or count == nobs) and method == 'jeffreys':
            # maybe a bug or different corner case definition
            pytest.skip("Skipping nobs 0 or count and jeffreys")
    
  10. josef-pkt commented on Feb 25, 2023

    @josef-pkt
    MemberAuthor

    proportion doesn't have method dicts like poisson rates method_names_poisson_2indep
    no obvious way to loop over all methods

  11. josef-pkt commented on Mar 12, 2025

    @josef-pkt
    MemberAuthor

    related: against Wald defaults with binomial

    Andersson, Per Gösta. n.d. “The Wald Confidence Interval for a Binomial p as an Illuminating ‘Bad’ Example.” The American Statistician, 1–6. https://doi.org/10.1080/00031305.2023.2183257.

    references the following for bias approximation

    Brown, Lawrence D., T. Tony Cai, and Anirban DasGupta. 2002. “Confidence Intervals for a Binomial Proportion and Asymptotic Expansions.” The Annals of Statistics 30 (1): 160–201. https://doi.org/10.1214/aos/1015362189.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions