-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
statsmodels.stats.rates.test_poisson_2indep has ZeroDivisionError if count2 is 0 #8313
Comments
The offending line is this one. statsmodels/statsmodels/stats/rates.py Line 141 in 96c41cd
If I am right about it being symmetric, it should boil down to
but there may be things in the one-sided tests in particular that I am forgetting. |
zero division should be a warning, but Python raises.
The problem is still present in my current PR #8166 score test works even for zero counts, (using my branch)
I think the fix should be something like the following which works automatically for scalar and vectorized rates edit |
current behavior in #8166 It looks like we got continuity with respect to count around zero Note, nan in exact-cond and cond-midp statistics are by design, not available
|
wald-log is messier, 3 divisions
also, we don't use asarray in the functions |
It works and it still returns a scalar (nulmpy scalar)
change will be in PR #8166 (fixing main would just cause messy merge conflicts) |
Describe the bug
When running
statsmodels.stats.rates.test_poisson_2indep
on data withcount2=0
, the function raises aZeroDivisionError
instead of computing the test statistics.Code Sample, a copy-pastable example if possible
Expected Output
I believe the test is symmetric, so
Output of
import statsmodels.api as sm; sm.show_versions()
INSTALLED VERSIONS
Python: 3.10.4.final.0
OS: Linux 5.10.114-1-MANJARO #1 SMP PREEMPT Mon May 9 07:52:55 UTC 2022 x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
statsmodels
Installed: 0.13.2 (/home/gereon/.local/lib/python3.10/site-packages/statsmodels)
Required Dependencies
cython: 0.29.28 (/usr/lib/python3.10/site-packages/Cython)
numpy: 1.22.3 (/usr/lib/python3.10/site-packages/numpy)
scipy: 1.8.1 (/home/gereon/.local/lib/python3.10/site-packages/scipy)
pandas: 1.4.2 (/usr/lib/python3.10/site-packages/pandas)
dateutil: 2.8.2 (/usr/lib/python3.10/site-packages/dateutil)
patsy: 0.5.2 (/home/gereon/.local/lib/python3.10/site-packages/patsy)
Optional Dependencies
matplotlib: 3.5.2 (/usr/lib/python3.10/site-packages/matplotlib)
backend: GTK3Agg
cvxopt: Not installed
joblib: 1.1.0 (/usr/lib/python3.10/site-packages/joblib)
Developer Tools
IPython: 8.3.0 (/usr/lib/python3.10/site-packages/IPython)
jinja2: 3.0.3 (/usr/lib/python3.10/site-packages/jinja2)
sphinx: 4.5.0 (/usr/lib/python3.10/site-packages/sphinx)
pygments: 2.12.0 (/usr/lib/python3.10/site-packages/pygments)
pytest: 7.1.2 (/usr/lib/python3.10/site-packages/pytest)
virtualenv: 20.11.0 (/usr/lib/python3.10/site-packages/virtualenv)
The text was updated successfully, but these errors were encountered: