R is't using my character random effects in a binomial glm

69 Views Asked by At

I get this error when I try to run my model using glm. Why won't R use my nested character nested effects?

model <- glm(Propotion ~ Parasites_box * Parasites_nest + Day_of_year + Site + (1|Subsite/Nestbox/Cavity_ID), data = data.ex, family = binomial)

Error in Subsite/Trapnest : non-numeric argument to binary operator

Using glmer gives me a different warning:

model <- glmer(Propotion ~ Parasites_box * Parasites_nest + Day_of_year + Site + (1|Subsite/Nestbox/Cavity_ID), data = data.ex, family = binomial)

Error in (function (fr, X, reTrms, family, nAGQ = 1L, verbose = 0L, maxit = 100L,  : 
  Downdated VtV is not positive definite
In addition: Warning message:
In eval(family$initialize, rho) : non-integer #successes in a binomial glm!

My model is testing if insects reduce their investment into a their nest (measured as the proportion of their nest filled with egg cells) if their nest becomes parasitized, or surrounding nests are parasitized. Parasites can be in the larger nesting box (with up to 18 individual nests) or within that specific insect nest. In my actual df, I have four sites, each with 6 unique subsites, each subsite with 3 unique nextboxes, and each nestbox with 18 unique cavity_IDs. E.g., Cavity s6_5 only exists in nestbox t11, which only exists in subsite s6, which only exists in site B. In other words, each cavity_ID, nestbox, and subsite exists uniquely. Here's a snippet of my data:

data.ex <- data.frame(Propotion  = c(0.645, 0, 0.805, 0.579, 0.167, 0), 
                  Parasites_box = c(7, 4, 6, 5, 3, 1),
                  Parasites_nest = c(2, 4, 0, 1, 0, 1),
                  Day_of_year = c(159, 167, 161, 172, 158, 164), 
                  Site = c('A', 'B', 'B', 'A', 'B', 'A'), 
                  Subsite = c('s1', 's6', 's7', 's1', 's7', 's2'),
                  Nestbox = c('t1', 't11', 't13', 't1', 't13', 't4'),
                  Cavity_ID = c('s1_3', 's6_5', 's7_2', 's1_1', 's7_6', 's2_3'))

Since I'm using a proportion (of nest space filled with cells), I should be using a binomial model. I'm wondering why I keep getting these errors and how to fix them?

1

There are 1 best solutions below

0
PBulls On

There are two problems here:

  1. glm does not do random effects, it has no idea what you mean by (1 | ...).
  2. You provide your outcome as a proportion. That's what you would do in a beta regression, but binomial (logistic) regression needs both the numerator and the denominator of the proportion as its response; alternatively, each separate measurement as a yes/no outcome.

There's a few other minor things, you don't have to provide this nesting structure for your random blocking for example since Cavity_ID uniquely identifies them, but unless you fix #2 your model doesn't stand much chance.

Speaking for the statistical rather than the programming aspect, from what little you've described about your data a beta regression might actually be more appropriate. You may have to switch to a package like glmmTMB, mgcv, or one of several other options to access that likelihood family.