Predicted probability values from Logistic regression are negative


I am trying to test if there is any relation between 2 variables and for this I have constructed a binary logistic regression model (where the dependent variable is 0 or 1), in Rstudio. Given the characteristics of this type of regression, values (fitted values) ​​should be considered as values ​​between 0 and 1, but this doesn’t happen in my model. When my teaching and participation patterns are distributed, the values ​​are more important than 1 and less than 0 (negative). What scares me is the fact that the model gives me odds for custom, ie out of range (0,1)!

Can someone help me?

Thank you,

Pedro C

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.


If you've never heard of a reprex before, you might want to start by reading the help page. The reprex dos and don'ts are also useful.

There's also a nice FAQ on how to do a minimal reprex for beginners, below:

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "")

For pointers specific to the community site, check out the reprex FAQ.

1 Like

I get the feeling that you are looking at the log odds and not the probabilities.

Lets assume you are predicting y ~ x. If you take the coefficients and apply the equation b0 + b1 * x, the result does not give you a probability, but the log odds which needs to be converted to a probability. One easy way would be to use the predict function with type as response.

See the example below (note that the model used in the example does not make any sense).

d <- data.frame(
  y = sample(c(0, 1), 30, replace = TRUE),
  x = rnorm(30)
fit <- glm(y ~ x, family = "binomial", data = d)
predict(fit, type = "response")
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.