13
$\begingroup$

My predictions coming from a logistic regression model (glm in R) are not bounded between 0 and 1 like I would expected. My understanding of logistic regression is that your input and model parameters are combined linearly and the response is transformed into a probability using the logit link function. Since the logit function is bounded between 0 and 1, I expected my predictions to be bounded between 0 and 1.

However that's not what I see when I implement logistic regression in R:

data(iris)
iris.sub <- subset(iris, Species%in%c("versicolor","virginica"))
model    <- glm(Species ~ Sepal.Length + Sepal.Width, data = iris.sub, 
                family = binomial(link = "logit"))
hist(predict(model))

enter image description here

If anything the output of predict(model) looks normal to me. Can anyone explain to me why the values I get are not probabilities?

$\endgroup$
1
  • 3
    $\begingroup$ Corone's answer below covers the details very nicely. The original figure you have above presents the log-odds values on the x-axis, which can be mathematically transformed to probabilities (i.e. as per Corone's answer, by passing back through the link function.) $\endgroup$ Commented Feb 3, 2013 at 23:01

1 Answer 1

17
$\begingroup$

The predict.glm method by default returns the predictors on the scale of the linear predictor. I.e. they haven't gone through the link function yet.

Try

hist(predict(model, type = "response"))

instead

enter image description here

$\endgroup$
1
  • 5
    $\begingroup$ You have done a great job mastering our markup and illustration capabilities in a short time: this answer is a nice example of that. Well done! $\endgroup$
    – whuber
    Commented Feb 4, 2013 at 16:25

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.