I have the following binary variable Y to be predicted as a function of two factors, say X1 and X2. The whole file is available here. X1 is binary and X2, categorical. When compiled, we find these proportions of 1s:

X2=0 X2=1 X2=2
X1 = 0 75/89 (84.3%) 62/77 (80.5%) 40/52 (76.9%)
X1 = 1 84/92 (91.3%) 52/72 (72.2%) 42/63 (66.6%)

Running with R a logistic regression using

M <- glm(Y ~ X1 + X2 + X1 : X2, family=binomial, data=dta)

we obtain the following coefficients:

            Estimate Std. Error z value Pr(>|z|)    
(Intercept)   1.6713     0.2661   6.280 3.39e-10 ***
X1            0.3995     0.3957   1.009    0.313    
X2           -0.2382     0.2186  -1.090    0.276    
X1:X2        -0.5308     0.3022  -1.757    0.079 .  

The intercept is straigthforward to interpret: un-logit this number $e^{1.67} / (1+ e^{1.67}) = .843$ is indeed the proportion obtained in the cell with factors X1,X2 = 0, 0.

To predict the result where X2 is 0 and X1 is 1, the log odd change is $e^{0.3995} = 1.49$, that is, that condition is 49% more present than the intercept. However, this equals $1.49 \times 0.844 = 1.257$ which is more than 100% of ones in that condition.

I must be doing something wrong, because this is a very poor fit to the data. Likewise, if I continue looking at the predictions for the other cells, I find more bad fits along with some accurate fits. Any help appreciated.


1 Answer 1


The coefficient for X1 is the difference in log-odds from the intercept, when X1 = 1 and X2 = 0. So you need to calculate:

# [1] 0.8880325

which is pretty close to what you observed.

The results aren't exact because you seem to have modeled X2 as a numeric variable rather than as a categorical predictor. You only have a single X1:X2 interaction coefficient. If you had modeled X2 as a 3-level categorical predictor you would have 2 such coefficients.

  • $\begingroup$ Thanks. How could I model X2 as categorical? Would spitting X2 into indicators X2a and X2b be enough? $\endgroup$ Commented Nov 4, 2022 at 18:08
  • 2
    $\begingroup$ @DenisCousineau let the software do it for you. In R: facX2 <- factor(X2). It's too easy to make mistakes when you try to do things like this yourself. $\endgroup$
    – EdM
    Commented Nov 4, 2022 at 18:12
  • $\begingroup$ Great, thank you! $\endgroup$ Commented Nov 4, 2022 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.