2
$\begingroup$

I have data that can be fit, more or less, by logistic growth functions. Hence I used this tutorial to do this.

Now I want to get an x value for a specific y value from the model. Maybe this is too trivial, but I could not find anything on the forums...or perhaps I was looking in the wrong way. For the below example, I would want to get the age at which Menarche is 0.5. In Excel I'd get the formula of the fit, solve it for x and put in y=0.5 ... but in R with logistic fit?

library("MASS")
data(menarche)
str(menarche)

summary(menarche)

plot(Menarche/Total ~ Age, data=menarche)

glm.out = glm(cbind(Menarche, Total-Menarche)~Age, family=binomial(logit), data=menarche)

plot(Menarche/Total ~ Age, data=menarche)
lines(menarche$Age, glm.out$fitted, type="l", col="red")
title(main="Menarche Data with Fitted Logistic Regression Line")
$\endgroup$
1
  • $\begingroup$ Note that 'how to do ______ in R' questions are generally off topic here, but this is ultimately a conceptual confusion, I think, & so sufficiently on topic here. $\endgroup$ Commented Jul 14, 2015 at 8:26

1 Answer 1

1
$\begingroup$

The key is to understand that the model you get is on the scale of the linear predictor. You need to take the link function into account. More specifically, the model is for log odds ln(p/(1-p)); so when p(Y = .5), logit(Y = 0). At that point you can solve for X algebraically: X = -coef(intercept) / coef(Age).

$\endgroup$
4
  • $\begingroup$ Hm, I was hoping R would allow me to use a simple function to spit out an x for a given y... $\endgroup$
    – user82243
    Commented Jul 14, 2015 at 14:02
  • $\begingroup$ @user82243, asking for R code is off topic here, as I noted above. However, this is pretty trivial once you understand what is going on; you could easily write your own function. $\endgroup$ Commented Jul 14, 2015 at 14:29
  • $\begingroup$ Ok, I got it working now. Would I be allowed to post the code of the solution, in case someone else is having the same problem? $\endgroup$
    – user82243
    Commented Jul 15, 2015 at 8:31
  • $\begingroup$ @user82243, you can post an answer to your own question with the code, if you want. $\endgroup$ Commented Jul 15, 2015 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.