0

I'm looking at debris ingestion in gulls. Each gull is listed by row. Columns contain the sex(0=male, 1=female), if they ate debris (0=no, 1=yes) and if I found any number of other items in their stomach, for this problem I'd like to see if sex and presence of debris influences the number of birds with Shells in their stomach (0=no shells, 1=shells). Debris prevalence is likely overdispersed and zero-inflated, but I'm not sure that matters if I'm using it as a factor to evaluate shell prevalence. Shell prevalence might be overdispersed and zero inflated as well.

I've plotted the data and want to test whether the differences seen in the plot are significant.

But when trying to run a zero-inflated negative binomial model I get many diff errors depending on how I set it up.

library (aod)
library(MASS)
library (ggplot2)
library(gridExtra)

library(pscl)
library(boot)
library(reshape2)

mydata1 <- read.csv('D:/mp paper/analysis wkshts/stats files/FOdata.csv')
mydata1 <- within(mydata1, {
  debris <- factor(debris)
  sex <- factor(sex)
  Shell_frags <- factor(Shell_frags)
})

summary(mydata1)

ggplot(mydata1, aes(Shell_frags, fill=debris))  +
  stat_count() +
  facet_grid(debris ~ sex, margins=TRUE, scales="free_y")


m1 <- zeroinfl((Shell_frags ~ sex + debris), data = mydata1, dist = "negbin", EM = TRUE) 
summary(m1)

number of birds consuming shells faceted by sex and presence of other debris

Error message:

Error in if (all(Y > 0)) stop("invalid dependent variable, minimum count is not zero") : 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
> summary(m1)
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'object' in selecting a method for function 'summary': object 'm1' 
  not found
Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36
  • Error in if `(all(Y > 0))` I don't see that line in your code. – SteveM Dec 05 '20 at 17:33
  • it's printed just above the other error messages....for whatever reason it separated the error messages when I pasted into this website – savewildlife Dec 05 '20 at 20:00
  • Where is Y defined/initialized? If you converted debris, sex and Shell_frags into factors, you can't do arithmetic on them. You can only count them. – SteveM Dec 05 '20 at 20:05
  • So if I don't convert Shell_frags into a factor then run it the same way.. I get the following errors: m1 <- zeroinfl((Shell_frags ~ sex + debris), data = mydata1, dist = "negbin", EM = TRUE) Error in zeroinfl((Shell_frags ~ sex + debris), data = mydata1, dist = "negbin", : object 'model_count' not found > summary(m1) Error in h(simpleError(msg, call)) : error in evaluating the argument 'object' in selecting a method for function 'summary': object 'm1' not found – savewildlife Dec 05 '20 at 20:18
  • If you want to filter out when debris, sex and Shell_frags are all 0, then do that before you convert them to factors. – SteveM Dec 05 '20 at 20:32
  • I don't think you can simply get rid of the zeros. This is prevalence data, without the zeros you don't have the full sample size, the and resulting 1s are meaningless without knowing the number of subjects per group. – savewildlife Dec 07 '20 at 13:40
  • I can get the zeroinfl function to work if I make EM = FALSE but only using Shell_frags and sex or debris but not sex + debris without generating an error. – savewildlife Dec 07 '20 at 13:44

0 Answers0