# How to find the inflection point in logistic regression using R?

I have conducted a binary logistic regression (with 7 predictor variables) in R using "year" as a random effect, i.e. a generalized linear mixed model (GLMM). For a few of the predictor variables, I would now like to find the inflection point, i.e. the value of the predictor variable for which the probability of the response variable being "1" equals 0.5. I would like both to produce a curve of this and to calculate the exact value, so that I won't have to read it from the curve (with the inaccuracy this would cause). A post from November 2013 made by Francis and edited by Scortchi touches on this topic (with a different purpose, though) and shares a specific code for producing such a curve (Logistic Regression and Inflection Point). However, I don't understand the 4th line of the code (newdata) and can't make the code work for my data. Is the 4th line something that has to be done in order to produce the curve? Might someone help me by uploading a more general code, or gently translating the referred one, for me to understand exactly how to fit my own data into the code? Also, if someone knows how to make R calculate the exact value, I would very much like to know. As you might be able to tell, I'm still learning R. I hope that someone can help.

• (1) Are all your effects linear in the logit? If not the inflection point doesn't necessarily coincide with a 0.5 probability for the response - which do you want? (2) At what values will you fix the other six predictors when calculating the inflection point of the one remaining predictor? – Scortchi - Reinstate Monica May 10 '14 at 12:06
• 1) I'm not completely sure what you mean by this, but the following should provide an answer: 6 of the 7 predictors are nummerical and the 7th is multi-categorical. The log-link regression is the basic multiple linear regression where the 6 nummerical predictors appear as "themselves" and the multi-cat. predictor is split up into dummies (the first of which is represented by the intercept). I would like for the inflection point to be at 0.5 - if the data allow this. 2) Maybe at their mean values? For the multi-cat. predictor, I guess that a specific category would have to be chosen? – user45324 May 10 '14 at 15:06
• (1) "Linear in the logit" means that the logit of the probability is a linear function of the predictor, not e.g. a polynomial. Note that logistic regression uses a logit link, not a log link; I assume this was a typo. (2) Rhetorical question really: the point's the inflection point will depend on the values of the other predictors; you can choose what to set them at if you're still interested. – Scortchi - Reinstate Monica May 11 '14 at 15:13

When the logit of the probability $\pi$ of the response's being 1 is linear in the $i$th predictor $x_i$, you can write the model like this

$$\log \frac{\pi}{1-\pi} = \beta_i x_i + \beta_0 +\sum_{j\neq i} \beta_j x_j$$

where the $\beta$s are the coefficients, & the $x_j$s the other predictors. The inflection point $x_i^*$ is where

$$\left.\frac{\partial^2 \pi}{(\partial x_i)^2}\right|_{x_i=x_i^*}=0$$

When you work that out it gives

$$x_i^*=\frac{-(\beta_0 +\sum_{j\neq i} \beta_j x_j)}{\beta_i}$$

& the corresponding probability, $\pi_i^*$, doesn't depend on the coefficients or other predictor values:

$$\pi_i^*=\frac{1}{2}$$

To extract coefficient estimates in R use coefficients(my.model). A convenient way to plot the curve is to make a data frame my.curve with $x_i$ varying over a range of interest & the $x_j$s constant (this is the line of code you queried) & then use predict(mymodel, newdata=my.curve, type="response") to obtain the predicted probabilities.