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)))
head(pred)
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?
family=binomial
argument. So let's reopen and write a short answer. $\endgroup$