How to find the value of a predictor variable necessary to attain a given probability in logistic regression? I've made a logistic regression model with a categorical response variable of two levels (YES/NO coded as 1/0) and a numerical predictor value (measured in ms).
I need to figure out a way to generate the value of the predictor variable (ms) needed to give a probability of $x$ for "YES". For example, what levels of the predictor variable (ms) are needed for the probability to be $0.3, 0.4, 0.5,$ etc.?
I have no idea conceptually how to achieve this as I'm pretty new to R. I can include my code if needed but I didn't think it was necessary since essentially what I need is someone to point me in the right direction.
 A: Let the regressor be $x$ and the response be $Y$ with possible values $0$ and $1$.  The logistic regression model is
$$p(x) = \Pr(Y=1) = \frac{1}{1+e^{-\alpha - \beta x}}.$$
Given estimates $\hat \alpha$ and $\hat \beta \ne 0$, this formula can be inverted to solve for $x$ in terms of any $p$ between $0$ and $1$:
$$x = \frac{1}{\hat\beta}\left(\log\left(\frac{p}{1-p}\right) - \hat\alpha\right).\tag{1}$$
Here is an example from the mtcars dataset.  It plots am against mpg, shows the curve $x\to p(x),$ and (using matching colors) locates the values of mpg corresponding to $p$ in the set $\{0.05, 0.10, 0.20, 0.50, 0.80, 0.90, 0.95\}$.  The visually evident fact that the intersections of all pairs of like-colored lines fall along the curve demonstrates the correctness of formula $(1)$ in this example.

Formula $(1)$ is implemented in the third line of the R code that produced this example.
fit <- glm(am ~ mpg, family=binomial(), data=mtcars) # Logistic regression
p <- c(.05,.10,.20,.50,.80,.90,.95)                  # Specify probabilities
x <- (log(p/(1-p)) - coef(fit)[1])/coef(fit)[2]      # Compute corresponding x's
i <- ordered(1:length(p))                            # Identify p's and x's for plotting
#
# Compute the fitted curve.
#
Z <- data.frame(mpg=with(mtcars, seq(min(mpg), max(mpg), length.out=101)))
Z$am <- predict(fit, Z, type="response")
#
# Plot everything.
#
library (ggplot2)
ggplot(mtcars, aes(mpg, am)) + 
  geom_hline(aes(yintercept=p, color=i), data.frame(p, i), alpha=0.8, show.legend=FALSE)+ 
  geom_vline(aes(xintercept=x, color=i), data.frame(x, i), alpha=0.8, show.legend=FALSE)+
  geom_point(size=2, alpha=0.25, fill="Black", shape=21) +
  geom_line(aes(mpg, am), Z, size=1.25, color="#303030") + 
  ylab("Probability(am=1)") + 
  ggtitle("Probability grid with associated regressor values") +
  theme(panel.grid=element_blank())

