I get an error when I try to fit Poisson model in a given dataset in R. Am struggling to understand the cause of the error.
library(COUNT) # Titanic dataset
data("titanic")
library(tidyverse)
# Number of missing values
titanic %>%
map_int(~sum(is.na(.)))
# Fit the Poisson regression model
poifit <- glm(survived ~ class, family = poisson, data = titanic)
titanic2 <- titanic %>%
mutate(across(.cols = everything(), ~as.factor(.)))
poifit2 <- glm(survived ~ class, family = poisson, data = titanic2)
I get the error:
Warning in Ops.factor(y, 0) : ‘<’ not meaningful for factors
Error in if (any(y < 0)) stop("negative values not allowed for the 'Poisson' family") :
missing value where TRUE/FALSE needed