0

I have built a logit model in R:

model <- glm(as.factor(y) ~ x, family = binomial(link = "logit"), data = data)

Using the predicted probabilities from this model, I'd like to solve for x when y = 0.95. I believe the predict() function only solves for y given certain values of x. How can I solve for x in this case? Is there another function in R that I can use that works with the logit link?

Aliv25
  • 13
  • 2
  • Use `predict` to generate y-predictions for a range of closely spaced x values and then swap the column meanings or choose the y -prediction that is closest to your 0.95 and use the x value that generated it. There's also the option of using the parameters from you modle and inverting the logit function. There are packages that solve the inverse problem "transparently". You would be looking for packages that have a `Quantile` function in them. – IRTFM Mar 12 '21 at 17:54
  • By swap the column meanings, do you mean to use predict(model, newdata = closely spaced x values named the same as data$x, type = 'response', se.fit = TRUE) – Aliv25 Mar 12 '21 at 18:11
  • I was thinking of predicting first and then swapping the meaning after. Get a set of x,y pairs with predict and then look at (plot) the y,x pairing. – IRTFM Mar 12 '21 at 18:14
  • 2
    Does this answer your question? [Regression (logistic) in R: Finding x value (predictor) for a particular y value (outcome)](https://stackoverflow.com/questions/32040504/regression-logistic-in-r-finding-x-value-predictor-for-a-particular-y-value) – TarJae Mar 12 '21 at 18:24
  • You can find the answer here: answer of Mr. Flick – TarJae Mar 12 '21 at 18:25
  • You are modeling `y` as a categorical factor, but then you want to find when it's equal to a numeric value of .95? That doesn't seem to make sense. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Mar 12 '21 at 18:29

0 Answers0