Regression (logistic) in R: Finding x value (predictor) for a particular y value (outcome) -


i've fitted logistic regression model predicts binary outcome vs mpg (mtcars dataset). plot shown below. how can determine mpg value particular vs value? example, i'm interested in finding out mpg value when probability of vs 0.50. appreciate can provide!

model <- glm(vs ~ mpg, data = mtcars, family = binomial)  ggplot(mtcars, aes(mpg, vs)) +      geom_point() +      stat_smooth(method = "glm", method.args = list(family = "binomial"), se = false) 

enter image description here

the easiest way calculate predicted values model predict() function. can use numerical solver find particular intercepts. example

findint <- function(model, value) {     function(x) {         predict(model, data.frame(mpg=x), type="response") - value      } }  uniroot(findint(model, .5), range(mtcars$mpg))$root # [1] 20.52229 

here findint takes model , particular target value , returns function uniroot can solve 0 find solution.


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -