0

My issue is perfect separation with a logistic model testing two binary factors and their interaction on the dependent variable. When I do not include the interaction term, the model works, when I include the interaction term I get

"PerfectSeparationError: Perfect separation detected, results not available"

There is already a question answered on perfect separation for logistic regression, but this question specifically pertains to perfect separation error with an interaction term in the model.

Here is my data Dataframe

My code:

endog_cols = df.columns[1:3]

exog_cols = df.columns[4:8]

logit2 = sm.GLM(df[endog_cols], df[exog_cols], family = sm.families.Binomial()).fit()
Bill P
  • 3,622
  • 10
  • 20
  • 32
David Drew
  • 1
  • 1
  • 3
  • Possible duplicate of [Unable to run logistic regression due to "perfect separation error"](https://stackoverflow.com/questions/34668868/unable-to-run-logistic-regression-due-to-perfect-separation-error) – Barker Oct 09 '18 at 16:18
  • Your intercept term is constant and can't be be fit as discussed [in this question](https://stackoverflow.com/questions/34668868/unable-to-run-logistic-regression-due-to-perfect-separation-error) – Barker Oct 09 '18 at 16:20
  • I understand that. However, I have a constant intercept in the same model without interaction and I get no error. Could I ask your advice on how I would revise the intercept so it doesn't cause the error? – David Drew Oct 09 '18 at 16:55
  • I can't speak for the specific implementation of GLM you are using, but most methods include the intercept as part of the model and therefore don't need you to specify it as a column. – Barker Oct 09 '18 at 20:05
  • statsmodels GLM method, the one I used, requires an intercept to be included manually in the exogenous vectors. – David Drew Oct 10 '18 at 20:33
  • For stats models that is only true when you aren't specifying the model using a formula: ["An intercept is not included by default and should be added by the user (models specified using a formula include an intercept by default)"](https://www.statsmodels.org/dev/generated/statsmodels.genmod.generalized_linear_model.GLM.html). This would also explain why it works when you don't include the interaction but breaks when you do. – Barker Oct 10 '18 at 21:25

0 Answers0