3
$\begingroup$

I have a categorical response which i want to predict, so i am in the process of developing a logistic model. I am using k-fold cross-validation for model selection. The first model, which was just an intercept model is throwing negative fitted values.

So i tried adding just 2 predictors to understand what was causing this, but the model with the 2 predictors is also predicting negative probabilities.

Below is the code that i used:

    logistic_null1 <- glm(SeriousDlqin2yrs ~ 1, family=binomial(), data=trainingdata)

logistic_null1 <- glm(SeriousDlqin2yrs ~ age + income, family=binomial(), data=trainingdata)

I checked if may be the response Y is not a factors but doesn't seem to be the case either

> class(trainingdata$SeriousDlqin2yrs)
[1] "factor"
> check3 <- as.data.frame(predict(logistic_null1, testdata))
> summary(check3)
 predict(logistic_null1, testdata)
 Min.   :-4.609                   
 1st Qu.:-3.047                   
 Median :-2.700                   
 Mean   :-2.703                   
 3rd Qu.:-2.346                   
 Max.   :-1.601 

What could cause this

$\endgroup$
3
  • $\begingroup$ Questions about how R code works are off topic here. In addition, please consider reading the documentation (?predict.glm). In particular, note the type argument & its default. $\endgroup$ Commented Mar 28, 2016 at 22:25
  • $\begingroup$ @gung: sorry about that. I was not sure whether it was because of my code or if such a scenario was possible in logistic. $\endgroup$
    – Raj
    Commented Mar 28, 2016 at 22:26
  • $\begingroup$ You have negative predicted values on the log odds scale. When you convert them into probabilities, they will be in the interval $(0,\ .5)$. $\endgroup$ Commented Mar 28, 2016 at 22:28

1 Answer 1

15
$\begingroup$

From ?predict.glm, you can read that by default the type of prediction will be the link function (log odds for logistic regression) instead of probabilities.

You can get predicted probabilities with :

predict(logistic_null1, testdata, type="response")
$\endgroup$
0

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