Help me calculate the interaction coefficient in logistic regression

Say we have a logistic regression of $$ln(\frac{\pi(x)}{1-\pi(x)})=\beta_0+\beta_1x_1 + \beta_2 x_2 + \beta_3x_1*x_2$$. IE we have our predictors for $$x_1$$ and $$x_2$$, and the final term is for the interaction of our two predictors.

I'm trying to understand the math behind $$\beta_3$$. Let's say $$x_1$$ and $$x_2$$ can only take on the values 0 or 1. I've looked up an explanation on the internet that says:

"$$\beta_3$$ is the difference between the log-odds ratio comparing $$x_1$$ = 1 vs $$x_1$$ = 0 when $$x_2$$ = 1 and the log-odds ratio comparing $$x_1$$ = 1 vs $$x_1$$ = 0 when $$x_2$$ = 0." That is like saying "this is the difference between "a and b" and "c and d". Like are we comparing (a-b) - (c-d)? Or (a/b)-(c/d)? Or (a-b)/(c-d)? Like I just...wut

I just CANNOT wrap my brain around this, no matter how many times I read it. I don't know what is being subtracted by what, what is being divided by what. It seems like there must be some sort of expression to derive $$\beta_3$$ based on everything we know about $$\beta_1$$ and $$\beta_2$$ but I just cannot get there.

I'm really frustrated. Help?

• How would you interpret it in a linear regression?
– Dave
Feb 25, 2022 at 23:34
• I believe @Dave's point is that logistic regression shares many characteristics with ordinary linear regression, so you can safely rely on your understanding of the latter to help you figure out the former. That's a useful thing to know! We happen to have quite a few posts about interactions and logistic regression. Perhaps one of the higher-voted ones will help relieve your frustration. How about stats.stackexchange.com/questions/57031?
– whuber
Feb 25, 2022 at 23:47
• Interactions in non-linear models are tricky. Here is an answer that discusses the interpretation on the probability scale with continuous variables, but also mentions the finite difference case. Feb 26, 2022 at 2:24

Let's break down that explanation

...the log-odds ratio comparing $$x_1=1$$ vs $$x_1=0$$ when $$x_2=1$$

A log-odds ratio is odds divided by another odds, and then we take the logarithm, so we know we have to put something in a numerator and something in a denominator. In the numerator, we have the log-odds when $$x_1=1$$ and $$x_2=1$$. In the denominator, we have the log-odds when $$x_1=0$$ and $$x_2=1$$.

$$\boxed{\log\bigg( \dfrac{P(Y=1\vert X_1=1, X_2=1)}{1 - P(Y=1\vert X_1=1, X_2=1)} \bigg/ \dfrac{P(Y=1\vert X_1=0, X_2=1)}{1 - P(Y=1\vert X_1=0, X_2=1)} \bigg)}$$

...the log-odds ratio comparing $$x_1=1$$ vs $$x_1=0$$ when $$x_2=0$$

This is the same as above but with all of the $$x_2=1$$ changed to $$x_2 = 0$$.

$$\boxed{\log\bigg( \dfrac{P(Y=1\vert X_1=1, X_2=0)}{1 - P(Y=1\vert X_1=1, X_2=0)} \bigg/ \dfrac{P(Y=1\vert X_1=0, X_2=0)}{1 - P(Y=1\vert X_1=0, X_2=0)} \bigg)}$$

$$\beta_3$$ is the difference...

This means that we subtract one quantity from the other, in particular the lower of the two log odds ratios above (second boxed expression) subtracted from the upper of the two log odds ratios (first boxed expression).

$$\beta_3 = \log\bigg( \dfrac{P(Y=1\vert X_1=1, X_2=1)}{1 - P(Y=1\vert X_1=1, X_2=1)} \bigg/ \dfrac{P(Y=1\vert X_1=0, X_2=1)}{1 - P(Y=1\vert X_1=0, X_2=1)} \bigg)\\ - \log\bigg( \dfrac{P(Y=1\vert X_1=1, X_2=0)}{1 - P(Y=1\vert X_1=1, X_2=0)} \bigg/ \dfrac{P(Y=1\vert X_1=0, X_2=0)}{1 - P(Y=1\vert X_1=0, X_2=0)} \bigg)$$