Repository navigation
ENH: rates, poisson means two-sample comparison rebased - #6677
Conversation
|
Hello @josef-pkt! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-05-05 21:08:15 UTC |
|
|
||
|
|
||
| print('debug') | ||
| print(stat_sample, mask.sum(), mean1, mean2) |
|
for unit test a brief search for R: base package rateratio.test by Faye has exact test that matches the confidence interval. package exactci also has poisson with exact pvalue and confint NCSS/PASS https://ncss-wpengine.netdna-ssl.com/wp-content/themes/ncss/pdf/Procedures/PASS/Tests_for_the_Ratio_of_Two_Poisson_Rates.pdf also quotes Gu I don't find an E-test in R with google search, another article, that I guess didn't look at Guogen Shan (2015) Exact unconditional testing procedures for comparing two independent Poisson rates, Journal of Statistical Computation and Simulation, 85:5, 947-955, DOI: 10.1080/00949655.2013.855776 |
|
this PR fails in lint check, but not in unit tests |
|
|
||
|
|
||
| # copied from statsmodels.stats.weightstats | ||
| def _zstat_generic2(value, std_diff, alternative): |
There was a problem hiding this comment.
remove, I only added this to have a standalone script that didn't depend on statsmodels
(for stackoverflow)
josef-pkt
left a comment
There was a problem hiding this comment.
looks fine
cleanup, unit tests against R, and merge
| return zstat, pvalue | ||
|
|
||
|
|
||
| def poisson_twosample(count1, exposure1, count2, exposure2, ratio_null=1, |
There was a problem hiding this comment.
rename to test_poisson_twosample or test_poisson_2indep
| return stat, pvalue | ||
|
|
||
|
|
||
| def etest_twopoisson(count1, exposure1, count2, exposure2, ratio_null=1, |
There was a problem hiding this comment.
rename etest_poisson_2indep ?
| rate1 = rate1_mle | ||
| rate2 = rate2_mle | ||
|
|
||
| # The sampling distribution needs to be based on the null hypotheis |
| y_total = y1 + y2 | ||
| stat = None | ||
| # TODO: why y2 in here and not y1, check definition of H1 "larger" | ||
| pvalue = proportion.binom_test(y1, y_total, prop=bp, alternative=alternative) |
There was a problem hiding this comment.
I think this is covered in R stats poisson test
| s1, pv1 = poisson_twosample(count1, n1, count2, n2, method='wald') | ||
| pv1r = 0.000356 | ||
| assert_allclose(pv1, pv1r*2, rtol=0, atol=5e-6) | ||
| print('wald', s1, pv1 / 2) # one sided in the "right" direction |
There was a problem hiding this comment.
remove print statements.
I guess this was just a example script file
| threshold = 100 | ||
| threshold = stats.poisson.isf(1e-13, max(mean1, mean2)) | ||
| threshold = max(threshold, 100) # keep at least 100 | ||
| y_grid = np.arange(threshold + 1) |
There was a problem hiding this comment.
needs options, kwds, for users to change this, see also #6676
I'm not sure it's the same grid, i.e. here it says y_grid
4a6b619 to
04d53e9
Compare
|
I don't find my original script file on my computer. I don't find a notebook either. |
|
comparing with GLM Poisson wald test doesn't match up exactly, score_test does |
04d53e9 to
8e4071e
Compare
|
corner case count1 = count2 = 0 In etest, I use a grid that contains the both zero point. This raised RuntimeWarning in the unit test. |
|
bug, missing unit test values are good, agrees with R stats |
|
current exact_cond and cond_midp are "minlike" library Note: midp doesn't have conf.int. If midp=FALSE, then conf.int is available |
|
The two-sided conditional exact test delegates to proportion.binom_test and then to scipy.stats.binom_test so "minlike" is inherited from scipy.stats, see also #2735 |
65a6090 to
4185259
Compare
|
another check tomorrow, then merge tost equivalence tests can be easily added. |
4185259 to
9c70bd6
Compare
|
This pull request introduces 4 alerts when merging 9c70bd6 into f6d0bf6 - view on LGTM.com new alerts:
|
|
all green |
rebased version of #2723 from 2015
original draft version for stackoverflow is in issue #2718
link again to my initial notes
https://github.com/josef-pkt/misc/wiki/Exact-and-Asymptotic-Tests---Rates,-Poisson