Skip to content

Commit 0569298

Browse files
committed
Handle changes in statsmodels behavior
In the latest stable release (0.14.0) statsmodels does not yield an exception anymore when data is perfectly separable this restores the expected behavior, though this may become a problem in future versions
1 parent a0e1716 commit 0569298

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pyseer/model.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ def fit_null(p, m, cov, continuous, firth=False):
107107
start_vec[0] = np.log(np.mean(p)/(1-np.mean(p)))
108108
null_mod = smf.Logit(p, v)
109109

110+
# statsmodels does not raise exceptions with perfectly separable data
111+
# but just a warning
112+
# this may stop working in the future
113+
# source: https://github.com/statsmodels/statsmodels/blob/e12de82fabd8e3fd71413aae384763c1442c4516/statsmodels/discrete/discrete_model.py#L186
114+
null_mod.raise_on_perfect_prediction = True
115+
110116
try:
111117
if continuous:
112118
null_res = null_mod.fit(disp=False)
@@ -173,6 +179,11 @@ def fit_lineage_effect(lin, c, k):
173179
axis=1)
174180

175181
lineage_mod = smf.Logit(k, X)
182+
# statsmodels does not raise exceptions with perfectly separable data
183+
# but just a warning
184+
# this may stop working in the future
185+
# source: https://github.com/statsmodels/statsmodels/blob/e12de82fabd8e3fd71413aae384763c1442c4516/statsmodels/discrete/discrete_model.py#L186
186+
lineage_mod.raise_on_perfect_prediction = True
176187
try:
177188
lineage_res = lineage_mod.fit(method='newton', disp=False)
178189

@@ -287,6 +298,11 @@ def fixed_effects_regression(variant, p, k, m, c, af, pattern,
287298
try:
288299
if continuous:
289300
mod = smf.OLS(p, v)
301+
# statsmodels does not raise exceptions with perfectly separable data
302+
# but just a warning
303+
# this may stop working in the future
304+
# source: https://github.com/statsmodels/statsmodels/blob/e12de82fabd8e3fd71413aae384763c1442c4516/statsmodels/discrete/discrete_model.py#L186
305+
mod.raise_on_perfect_prediction = True
290306

291307
res = mod.fit()
292308
intercept = res.params[0]
@@ -298,6 +314,11 @@ def fixed_effects_regression(variant, p, k, m, c, af, pattern,
298314

299315
else:
300316
mod = smf.Logit(p, v)
317+
# statsmodels does not raise exceptions with perfectly separable data
318+
# but just a warning
319+
# this may stop working in the future
320+
# source: https://github.com/statsmodels/statsmodels/blob/e12de82fabd8e3fd71413aae384763c1442c4516/statsmodels/discrete/discrete_model.py#L186
321+
mod.raise_on_perfect_prediction = True
301322

302323
start_vec = np.zeros(v.shape[1])
303324
start_vec[0] = np.log(np.mean(p)/(1-np.mean(p)))

tests/model_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
try:
1010
smf.Logit
1111
except AttributeError:
12+
import statsmodels
1213
smf.Logit = statsmodels.discrete.discrete_model.Logit
1314
from pyseer.model import pre_filtering
1415
from pyseer.model import fit_null

0 commit comments

Comments
 (0)