You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FAQ/DOC/ENH k-sample binomial proportion, joint and individual hypothesis tests #6380
Suppose we have k-sample binomial proportions, i.e. 2 x k contingency table with independent columns.
what can we test if the overall hypothesis is that all proportions are the same?
joint test: all proportions equal to average proportion
individual, vectorized test for equality to average maybe with multiple testing correction, or using joint test as gate keeper to preserve overall FWER, or FDR if some nulls might fail
all pairwise, ...
I don't remember what we have for this case. I guess there are some missing hypothesis tests for the k-sample version.
Proper distribution would have to take into account that the average depends on each proportion. There is a literature for this but I don't remember much.
k-sample equality of mean would be just an ANOVA for proportions.
I'm pretty sure we don't have it.
But maybe standard ANOVA would apply with pooled variance under the null using normal or chisquare distribution similar to proportions_ztest.
update I think this is Cochran-Mantel-Hanszel test available in Stratified contingency table.
I used an example in the meta-analysis notebook for k-sample proportions.
statsmodels.stats.proportion.proportions_chisquare_allpairs proportions_chisquare_pairscontrol statsmodels.stats.proportion.proportions_chisquare "This function provides a similar interface to chisquare tests as prop.test in R", docstring mentions contingency tables in scipy.stats but does not mention statsmodels contingency table support (i.e. docstring was never updated)
no examples, so not immediately obvious what those do, besides guessing based on function names
Upvoting. Would be great to have a full analog to R's prop.test. I think you're right, it's mostly available, but would be useful/convenient to have a similar API to prop.test, with confidence intervals provided as well.
From what I remember R's prop.test handles too many cases in one function. I had tried to split this up into easier to understand functions, but without examples those functions are still not "obvious".
What confidence intervals are directly related to this? This is a joint test over several independed proportions in the main case. That wouldn't have directly a confidence interval, or does it? The confidence intervals for individual proportions are in a separate function.
I think we need a structured overview docs for this, so it's easier for users to find which function handles which case.
It would be helpful if you can figure out what is missing and find a good way to add it.
At the time I wrote that code I wanted standalone functions which are also easy to use when we just need a specific item.
In other cases like weightstats, multiple comparison (tukey-hsd) or contingency tables we used classes which makes it easier to bring everything together in a single place.
For the stats functions like proportions, I haven't figured out how to better structure it in a class (especially because I also wanted to add power/sample size computations and effectsizes to it)
What triggered it for me this time was that I couldn't answer a stackoverflow question, because I didn't remember what we have already and whether things we might have would apply to the case in question.
So it would be good to improve discoverability and usability in this area, and add missing pieces.
I just ran into some literature for this, essentially extensions to what we have now for the 2-sample case to the k sample - 2 proportion case. (edit: see next comment)
I didn't look closely at any of them
Tang is current article that collects most results, based on quick skimming
Nam is one of the original, several similar by Gaart, Nam (I guess similar to 2-sample case)
AFAIU, the null is equal relative risk but not equal to 1 with confidence intervals for it, the part to estimate and confint is closer to meta-analysis applications.
Tarone is a commonly cited article for score tests with nuisance parameters
Lipsitz, Stuart R., Keith B. G. Dear, Nan M. Laird, and Geert Molenberghs. 1998. “Tests for Homogeneity of the Risk Difference When Data Are Sparse.” Biometrics 54 (1): 148–60. https://doi.org/10.2307/2534003.
If I skimmed correctly, then sparse means asymptotic is in large, increasing number of strata.
Several of the other articles have fixed number of strata and increasing strata/group size
2 x k : k independent samples of a binomial proportion, focus is on individual proportions
2 x 2 : two samples of a binary/binomial proportion
2 x 2 x k : stratified 2 x 2 that's in the last comment and meta-analysis, we have a set of 2x2 comparisons, focus is on the comparison between 2 proportions across "strata"
in terms of model:
2 x 2 x k is binary or binomial count endog, one binary exog and a stratification exog. Under the null, there is not interaction between binary exog and stratification variable.
Activity
josef-pkt commentedon Jan 3, 2020
k-sample equality of mean would be just an ANOVA for proportions.
I'm pretty sure we don't have it.
But maybe standard ANOVA would apply with pooled variance under the null using normal or chisquare distribution similar to proportions_ztest.
update I think this is Cochran-Mantel-Hanszel test available in Stratified contingency table.
I used an example in the meta-analysis notebook for k-sample proportions.
josef-pkt commentedon Jan 9, 2020
R
prop.testincludes the anova caseexample here
https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/prop.test
josef-pkt commentedon Jan 12, 2020
maybe this is already mostly available
statsmodels.stats.proportion.proportions_chisquare_allpairsproportions_chisquare_pairscontrolstatsmodels.stats.proportion.proportions_chisquare"This function provides a similar interface to chisquare tests as prop.test in R", docstring mentions contingency tables in scipy.stats but does not mention statsmodels contingency table support (i.e. docstring was never updated)no examples, so not immediately obvious what those do, besides guessing based on function names
vsriram11 commentedon Jan 13, 2020
Upvoting. Would be great to have a full analog to R's prop.test. I think you're right, it's mostly available, but would be useful/convenient to have a similar API to prop.test, with confidence intervals provided as well.
josef-pkt commentedon Jan 13, 2020
From what I remember R's prop.test handles too many cases in one function. I had tried to split this up into easier to understand functions, but without examples those functions are still not "obvious".
What confidence intervals are directly related to this? This is a joint test over several independed proportions in the main case. That wouldn't have directly a confidence interval, or does it? The confidence intervals for individual proportions are in a separate function.
I think we need a structured overview docs for this, so it's easier for users to find which function handles which case.
It would be helpful if you can figure out what is missing and find a good way to add it.
aside: The last time I was seriously working on proportions I tried to get everything for the one-sample case
https://github.com/josef-pkt/misc/blob/proportion_one/notebooks/proportion_one_power.ipynb
But supporting two- and k- sample cases is still incomplete, even though we already have more than I remembered.
josef-pkt commentedon Jan 13, 2020
About code organization in
proportionsAt the time I wrote that code I wanted standalone functions which are also easy to use when we just need a specific item.
In other cases like weightstats, multiple comparison (tukey-hsd) or contingency tables we used classes which makes it easier to bring everything together in a single place.
For the stats functions like proportions, I haven't figured out how to better structure it in a class (especially because I also wanted to add power/sample size computations and effectsizes to it)
What triggered it for me this time was that I couldn't answer a stackoverflow question, because I didn't remember what we have already and whether things we might have would apply to the case in question.
So it would be good to improve discoverability and usability in this area, and add missing pieces.
josef-pkt commentedon Jan 13, 2020
If there ain't no docs, look at the unit tests
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/stats/tests/test_proportion.py#L211
uses the smoker/patients example
the only asserts for it seems to be in the Mixin
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/stats/tests/test_proportion.py#L169
and an extra assert for the scalar case against ztest
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/stats/tests/test_proportion.py#L569
josef-pkt commentedon Nov 26, 2020
I just ran into some literature for this, essentially extensions to what we have now for the 2-sample case to the k sample - 2 proportion case. (edit: see next comment)
I didn't look closely at any of them
Tang is current article that collects most results, based on quick skimming
Nam is one of the original, several similar by Gaart, Nam (I guess similar to 2-sample case)
AFAIU, the null is equal relative risk but not equal to 1 with confidence intervals for it, the part to estimate and confint is closer to meta-analysis applications.
Tarone is a commonly cited article for score tests with nuisance parameters
Nam, Jun-Mo. 1994. “Sample Size Requirements for Stratified Prospective Studies with Null Hypothesis of Non-Unity Relative Risk Using the Score Test.” Statistics in Medicine 13 (1): 79–86. https://doi.org/10.1002/sim.4780130109.
Tang, Yongqiang. 2020. “Score Confidence Intervals and Sample Sizes for Stratified Comparisons of Binomial Proportions.” Statistics in Medicine 39 (24): 3427–57. https://doi.org/10.1002/sim.8674.
Tarone, Robert E. 1988. “Homogeneity Score Tests with Nuisance Parameters.” Communications in Statistics - Theory and Methods 17 (5): 1549–56. https://doi.org/10.1080/03610928808829697.
Lipsitz, Stuart R., Keith B. G. Dear, Nan M. Laird, and Geert Molenberghs. 1998. “Tests for Homogeneity of the Risk Difference When Data Are Sparse.” Biometrics 54 (1): 148–60. https://doi.org/10.2307/2534003.
If I skimmed correctly, then sparse means asymptotic is in large, increasing number of strata.
Several of the other articles have fixed number of strata and increasing strata/group size
related
josef-pkt commentedon Nov 26, 2020
to clarify the different setups (AFAICS)
in terms of model:
2 x 2 x k is binary or binomial count endog, one binary exog and a stratification exog. Under the null, there is not interaction between binary exog and stratification variable.