Solving logistic regression equation for slope

94 Views Asked by At

I've calculated a logistic regression model involving two variables $X_1$ and $X_2$ and their interaction $X_1 \times X_2$ and obtained regression coefficients for each.

The equation takes following linear form: $$ \text{logit }p(X_1,X_2) = \beta_0 + \beta_1 \cdot X_1 + \beta_2 \cdot X_2 + \beta_{\text{interaction}} \cdot X_1 \cdot X_2 $$

If got the mathematics correct this should correspond to the non-linear form: $$p(X_1,X_2) = \frac{1}{1 + \exp\left(-\left(\beta_0 + \beta_1 \cdot X_1 + \beta_2 \cdot X_2 + \beta_{\text{interaction}} \cdot X_1 \cdot X_2\right)\right)}$$

The regression coeffiecients I obtained are the following: $\beta_0$ = 0.31, $\beta_1$ = -5.63, $\beta_2$ = -0.02, $\beta_\text{interaction}$ = 0.45; Based on the parameters I can plot the probability against a range of value for $X_1$ (in my case this is named DeltaT) and across values of $X_2$ (in the plot as single panels and called Tamb) which looks like: Logistic regression with interaction

From the plot I can see that there is an point of inflection at appr. $X_2$ = 12.5, i.e. where the slope of the line changes from negative to positive (or vice versa).

Now, I'd like the get the exact point when this happens. In other words at which value of $X_2$ does the slope change (at $X_1$ = 0).

From manual simulations and numerically obtaining the point where the slope changes, it seems this is at $\frac{-\beta_1}{\beta_\text{interaction}} = \frac{-1*(-5.63)}{0.45} = 12.51 $. [As a note why I am confused: I'd have set $X_1$ in the first linear equation to 0 and solved for $X_2$ which would then have been $X_2 = \frac{-\beta_0}{\beta_2}$?, but that's not how it works.]

I guess obtaining the slope (and where it changes) can be done by calculating the first derivative of the equation with respect to $X_2$. Setting the derivative equal to zero should obtain the point where the slope becomes zero? However, I don't get the mathematical steps behind that, as in the end this seems to be solved by just two regression coefficients(?).

2

There are 2 best solutions below

0
On BEST ANSWER

Evidently, $\beta_1 X_1 + \beta_{inter}X_1 X_2 = X_1(\beta_1 + \beta_{inter} X_2)$. The sign of the term in parentheses is what determines whether the effect of $X_1$ increasing is either an increase or a decrease in the probability. The way to prove it is simply to rewrite the expression for the probability as $$ p(X_1, X_2) = \frac{1}{1 + \exp(-\beta_0) \exp(-\beta_2 X_2)\exp[-X_1(\beta_1 + \beta_{inter} X_2)]}. $$ $\exp(-\beta_0)$ and $\exp(-\beta_2 X_2)$ are positive numbers, so if $\exp[X_1(\beta_1 + \beta_{inter} X_2)]$ increases, then the denominator decreases, and vice versa. So the sign of $\beta_1 + \beta_{inter} X_2$ is the key.

In your numerical experiments you confirmed it: $\beta_1 + \beta_{inter} X_2 \approx -5.63 + 0.45 * 12.5 \approx 0.0005$. So the value you want is exactly $\beta_1 + \beta_{inter} X_2 = 0 \Leftrightarrow X_2 = -\frac{\beta_1}{\beta_{inter}}$, as you guessed.

0
On

Let $z = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_{\text{interaction}} x_1 x_2 $ so that the probability simply writes $p=\sigma(z)$ with the logisitic function $\sigma(.)$.

Using chain rule $$ \frac{dp}{dx_1} = \frac{dp}{dz} \frac{dz}{dx_1} = \sigma(z) [1-\sigma(z)] (\beta_1+\beta_{\text{interaction}} x_2) $$

This partial derivative is null when $\beta_1+\beta_{\text{interaction}} x_2=0$ as you discovered.