I have litte experience with GLMM's and I need to use Hurdle models for the first time, but I'm really confused about the random effect part.
I have a dataframe with counts of flies caught in traps with 2 different luring products (same nr of traps for each product). The traps were emptied every 3-4 days for a few months. The sex and morph of the flies was determined. The df looks like this:
Date value morph sex product
2016-04-05 5 Winter M ACV
2016-04-05 1 Summer M ACV
2016-04-05 18 Winter F ACV
2016-04-05 3 Summer F ACV
2016-04-05 0 Winter M FRA
2016-04-05 0 Summer M FRA
2016-04-05 0 Winter F FRA
2016-04-05 0 Summer F FRA
2016-04-08 0 Winter M ACV
2016-04-08 0 Summer M ACV
...
I need to add date as random effect so I use GLMM. Because I have a lot of zeros, a normal GLMM doesn't work. I read about hurdle models and I think these are fitting for the data. Better than zero-inflated, because I can't have 0's after "taking the hurdle". (based on this post: What is the difference between zero-inflated and hurdle distributions (models)? )
I've come up with this so far:
# binairy part
hurP1 <- glmmadmb(value ~ product * sex * morph + (1 | Date),
data = data2, family = "binomial")
# truncated at 0 part
hurP2 <- glmmadmb(value ~ product * sex * morph + (1 | Date),
data = subset(data2, value > 0), family = "truncnbinom1")
In the example of the glmmADMB package,
http://glmmadmb.r-forge.r-project.org/glmmADMB.html
they use formatted response data (nz
) in the binairy part of the model and I don't understand why. They only take Y > 0, but this model is checking the 0's? Why remove them?
EDIT Niek answered my question about the response data. But the random part of my model is still not correct, I get this error:
Error in Droplevels(eval(parse(text = x), data)) :
all grouping variables in random effects must be factors
So this question is still standing:
Also, I'm not sure if my random effect part is correct like this? I don't have nesting and I see nesting or blocking factors in every example I encounter.
EDIT2 Forgot to run the script lines that turn Date into a vector with factors... All problems solved now!