3
$\begingroup$

I have a binary dependent variable (R) and four numeric independent variables (Q, M, S, T) and want to examine coefficients for them.

Here is my glm code in R:

fit = glm(R ~ Q + M + S + T, data=data, family=binomial())

When I run predict(fit), I get a lot of predicted values greater than one (but none below 0 so far as I can tell). I have tried bayesglm and glmnet per suggestions to similar questions but both are a little over my head and the output I did get didn't seem to fix my problem.

I want to know: A) Is this typical of logistic regression? B) If not, how do I fix it?

$\endgroup$
1
  • 4
    $\begingroup$ The OP's mistake is a pure coding question, but what led the OP to realise there was a problem (i.e. whether there could be predicted values above 1) is a statistical issue. I think "if you are producing fitted values above 1 in a logistic regression, then you must have made a mistake in your code" is a learning point that belongs on a statistics site. $\endgroup$
    – Silverfish
    Commented Oct 2, 2015 at 17:01

1 Answer 1

8
$\begingroup$

Note that predict has a "type= c("link", "response", "terms")" argument:

type    
the type of prediction required. The default is on the scale of the linear 
predictors; the alternative "response" is on the scale of the response variable. 
Thus for a default binomial model the default predictions are of log-odds 
(probabilities on logit scale) and type = "response" gives the predicted probabilities. 
The "terms" option returns a matrix giving the fitted values of each term in the model 
formula on the linear predictor scale.

Default is link but you are looking for response.

Is it typical of logistic regression ? Not that I know. It is mostly a choice of implementation, both quantities can be useful depending on the situation. Python sk-learn implements both predict_proba and predict_log_proba.

$\endgroup$
2
  • $\begingroup$ Thanks! I initially thought I saw responses greater than one but I guess I was misreading. Everything looks good now. $\endgroup$ Commented Oct 2, 2015 at 16:14
  • 1
    $\begingroup$ Thanks, adding the info about Python was quite nice, and I agree with "It is mostly a choice of implementation, both quantities can be useful depending on the situation" - but that wasn't quite what I meant ;) More a (brief!) explanation about what the two quantities actually represent statistically (and an affirmation that the fitted response would, indeed, be between 0 and 1 ... the OP was originally confused why the fitted response, which represented a probability could be above one, and the answer is that it isn't!). $\endgroup$
    – Silverfish
    Commented Oct 2, 2015 at 19:53

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.