Repository navigation
ENH: add two independent proportion inference rebased - #6675
Conversation
|
rebased, one minor merge conflict, no additional changes compared to old PR |
| from statsmodels.stats.weightstats import _zstat_generic2 | ||
|
|
||
|
|
||
| class Holder(object): |
There was a problem hiding this comment.
use generic holder class now, currently tools/testing
|
|
||
|
|
||
| def confint_proportion_2indep(count1, nobs1, count2, nobs2, method=None, | ||
| compare='diff', alpha=0.05, correction=True): |
There was a problem hiding this comment.
function looks fine to me when skimming the code
|
code duplication
plus contingency table version for some of it. This contains power function for normal with alternative dependent variance as extra enhancement. |
|
notebook return of confint function returns tuple |
|
from notebook, this seems to be what's currently implemented in the test and confint functions |
20c0ba2 to
776a8b0
Compare
|
rebased after merging meta-analysis into master |
| ----- | ||
| Status: experimental, API and defaults might still change. | ||
| Insufficiently tested, more ``methods`` will be added. | ||
|
|
There was a problem hiding this comment.
References is missing
need description of methods
|
codacy complains about some unused variables, 2 in proportions.py and several in unit tests |
| raise ValueError('method not recognized') | ||
|
|
||
| elif compare == 'ratio': | ||
| ratio = p1 / p2 |
| raise ValueError('method not recognized') | ||
|
|
||
| elif compare == 'odds-ratio': | ||
| odds_ratio = p1 / (1 - p1) / p2 * (1 - p2) |
| Baptista–Pike exact conditional 1.00 195 5.28 | ||
| Baptista–Pike mid-p 1.33 99 4.31 | ||
| Agresti–Min exact unconditional 1.19 72 4.10 | ||
| ''' |
There was a problem hiding this comment.
pointless-string-statement
try # pylint: disable=W0105
| x = x0 + x1 | ||
| n = n0 + n1 | ||
| p0 = x0 / n0 | ||
| p1 = x1 / n1 |
|
This PR is missing the equivalence TOST tests see note, |
|
|
||
| def _std_2prop_power(diff, p2, ratio=1, alpha=0.05, value=0): | ||
| """compute standard error under null and alternative for 2 proportions | ||
|
|
There was a problem hiding this comment.
only for "diff" ?
nobs_ratio would be more explicit, if it is ratio of nobs
There was a problem hiding this comment.
in power computation, I always use ratio for nobs-ratio.
but for 2sample proportion, we also have risk-ratio and odds-ratio
|
from notebook: check consistency between confint and hypothesis test: score method for risk ratio is inconsistent |
|
what is It has unit test coverage but is not available through a non-private function. |
|
current methods edit added Y for score confint
in meta-analysis effect size, not yet checked: overlap with contingency tables: at least wald versions should be there e.g. log-or and log-rr |
|
This PR does not include any exact methods, see #6676 but only for equality testing (AFAIR). All methods here are asymptotic with small sample adjustments, transformation and artificial observations. |
|
Returns:
|
|
score confidence interval looks like rootfinding and not a direct implementation: see also #2722 for GLM update inverting score test works fine in my example, One problem is how robust we make the rootfinder. Right now I'm using brentq with some approximate bounds which might fail to produce opposite signs. Also there might be problems with corner solutions, e.g. values going to zero. |
|
valid input ranges I used the wrong There should be a check that the user provides a valid |
|
another issue: |
|
another consistency check: |
|
next question: Can I get the power generically, i.e. for any method available in the test and tost function? the If I have the props under the alternative, then I could do the full binomial power version, but would need to evaluate (run hypothesis test on) all points on grid. That's what I was doing for "exact" power. If I cannot do it generically this way, then I need mean and variance of the test statistic under the alternative (i.e. noncentrality) for each method similar to the current one for diff-wald. test_proportions_2indep works vectorized for all compare and methods PASS Superiority by a Margin for two proportions chapter 205 (printed several years ago) uses I guess my naming with |
|
getting close, I have most of what I want in this round, I'm skipping power this time now also equivalence TOST tests 'logit-smoothed' for odds-ratio is available in hypothesis test and tost but not in confint. needs another check for method names also need to check that we have consistent use of abbreviation for the compare statistic, e.g. "or" for "odds-ratio" docs and references, e.g. do corner cases, AFAIR, I never checked corner cases counts=0 or counts=nobs test noise: I get some warnings when running the unit tests, e.g. |
|
silly naming mistake: proportion is singular: name should be plural for 2 and k-sample tests |
|
replicating 2 sample tests using GLM works, but not with irls, see #3703 Note: endog in GLM binomial is using identity link replicated related aside: what's the status of the |
|
azure py 3.6 failed in this PR is green |
|
|
|
standard errors for two sample proportions ? and/or for transformed statistics None of the functions in this PR provides standard errors. Can we get everything together in one place? Not now, or at most partially. maybe a wrapper class or function to provide summary for params, hypo test and confint. |
|
great when things just work GLM fit_constrained + score_test == 2 proportion test with score and correction=False (Farrington-Manning) |
|
Holdertuple doesn't work by default for other than test results, e.g. power, confint. Also power returns a single value if not return_results. I'm about ready to stop and merge. |
|
I will merge when green |
|
I still only have a partial overview of what we have for proportions # 6399 partial overlap with existing functions
|
|
completely green, merging |
rebased version of #4829