# Why are my fitted values returning greater than 1 in GLM?

I have an internal model that I unfortunately cannot share, but I've reproduced the issue below. My model has a binary target of 0 and 1. After running the predict function with type = "response", the values are still greater than 1 or less than 0 for some observations:

require(tidyverse)
data("iris")
iris
iris.model <- iris %>%
mutate(isSetosa = case_when(Species == "setosa" ~ 1,
TRUE ~ 0)) %>%
select(-Species)

mymodel <- glm(isSetosa ~ ., data = iris.model)
pred <- as.data.frame(predict(mymodel, type = "response")) %>%
rename("preds" = 1)  %>%
mutate(newpred = exp(preds)/(1+exp(preds)))

preds   newpred
1 0.9789278 0.7268954
2 0.8442979 0.6993696
3 0.9021272 0.7113864
4 0.8263080 0.6955737
5 0.9966096 0.7303915
6 1.0169842 0.7343847


Given the fitted values are the same whether I choose "link" or "response" for type, I manually calculated the probabilities for each observation, but they seem lower than I would expect for the iris dataset.

What am I doing wrong here?

• You forgot the family argument in your glm call. I do that all the time. Oct 5, 2020 at 21:02
• This question may be simple, but it is not off-topic. "It needs statistical expertise to understand or answer", which is a direct quote from our on-topic page. I don't see someone at StackOverflow understanding that you need to specify the family=binomial argument. So let's reopen and write a short answer. Oct 5, 2020 at 21:08
• Thanks, all, for the sanity check. I figured it would be something simple. Oct 6, 2020 at 12:07
• For future reference, when you post here, you would do best to use base R code. Not everyone will know how to read tidyverse type code. Oct 7, 2020 at 19:32

You forgot the family argument in the glm call. You probably wanted family=binomial or family= binomial(link = "logit").