Error in glm.nb : if (any(y < 0)) stop("negative values not allowed for the 'Poisson' family") : missing value where TRUE/FALSE needed

Hello, I am running a negative binomial model using the glm.nb function from the MASS package. When I run the model the following error appears:

Error in if (any(y < 0)) stop("negative values not allowed for the 'Poisson' family") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, 0) : ‘<’ not meaningful for factors

My covariant of interest is numeric count data from 0-1900. I have converted this into numeric using the as.numeric function. My model looks like this:

model <- glm.nb(non_house_contact ~ wave, data = df)

I am not sure why this error is occurring. Any help would be appreciated. Thanks.

it seems your conversion to numeric didn't 'take'
Perhaps share the code that you had used for that purpose ?

Hi, I used the code below to convert to numeric:

as.numeric (non_house_contact)

Here is the str()

$ Wave             : chr [1:7] "wave1" "wave3" "wave5" "wave3" ...
 $ Non_house_contact: num [1:7] 2 1 7 1 1 4 100
 $ Sex              : chr [1:7] "F" "F" "F" "M" ...
 $ Caring           : chr [1:7] "Yes" "Yes" "Yes" "No" ...
 $ Well being       : chr [1:7] "A little" "A lot" "A little" "No change" ...

Thanks!

The mysteries are multiplying....

as.numeric (non_house_contact)

this code, has no apparent relation to 'df' which is the object passed to glb.nm in your example.
furthermore the str() if it is of df appears to show a different capitalisation Wave rather than wave etc, and R is case sensitive and will see these as different.

Hopefully these clues will be enough for you to progress.
If not, then you could get additional help by creating a more complete reprex, which you can read about how to do here

Maybe that is where I am going wrong then! Thanks

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.