Home > Net >  Error with Poisson regression with a log link and factor as outcome
Error with Poisson regression with a log link and factor as outcome

Time:04-21

I´m having some problems trying to run a Poisson regression with link = "log":

model <- glm(formula = var1 ~ var2, 
              family = poisson(link = "log"), 
              data = a)

var1 is a categorical variable (class: factor) with two categories: "with depression" and "without depression". var2 is another categorical variable (class: factor) with four age categories.

This error keeps coming up:

Error in if (any(y < 0)) stop("negative values not allowed for the 'Poisson' family") : 
missing value where TRUE/FALSE is necessary.
Warning message:
  In Ops.factor(y, 0) : '<' not meaningful for factors

When I run the model with family = binomial the problem does not appear.

CodePudding user response:

As the comments have said your outcome is binary so you might want to stick with logistic regression, or binomial regression with log link.

But there are some circumstances where Poisson regression with binary outcome is appropriate. In this case you'll need to recode your outcome as numeric (0 vs 1), because in R Poisson regression cannot use factors as outcomes.

To understand the error message, before Poisson regression R will check for negative values in the response. But with a factor as outcome y<0 returns NA, which causes the test to fail.

  • Related