0

I am trying to build a glmm in R but constantly get error messages (I am a complete beginner).

I have conducted an experiment with Camera traps in which I tested, if they react to a target, that I pulled in front of them, so my response variable is binomial. I try to build a GLMM, in which all the variables are fixed factors and day (in which the experiment was conducted is a random factor). Could anyone more experienced tell me what I am doing wrong (I first try only with one explanatory variable)?

I tried it with the glmm() and with lmer():

library(glmm)
set.seed(1234)
ptm <- proc.time()
Detections <- glmm(Detection ~ 0 + Camera, random = list(~ 0 + Day), 
    varcomps.names = c("Day"), data = data1, family.glmm = bernoulli.glmm, 
    m = 10^4, debug = TRUE)`

This one produces an obscenely large glmm, even with the minimal dataset.

and with

library(lme4)
Detections_glmm <- lmer(Detection ~ Camera + (1|Day), family="binomial")

This one gives the following error message:

Error in lmer(Detection ~ Camera + (1 | Day), family = "binomial") : 
  unused argument (family = "binomial")

Here is a minimal df:

data.frame(
    Detection = c(1, 0, 0, 1, 1, 1, 1, 0, 0, 0),
             Temperature = as.factor(c("10","10","10","10","10","20","20",
                                       "0","0","0")),
                Distance = as.factor(c("75","75","75","225","225","225",
                                       "75","150","150","150")),
                    Size = as.factor(c("0","0","0","0","1","1","1","1",
                                       "2","2")),
                   Light = as.factor(c("1","1","1","1","1","0","0","0",
                                       "0","0")),
                  Camera = as.factor(c("1","1","2","2","2","3","3","3",
                                       "1","1")),
                     Day = as.factor(c("1","1","1","2","2","2","3","3",
                                       "3","2"))

And Information about the variables:
Response variable:
Detection (binomial)

Explanatory variables:
Temperature of bottle: (0, 10, 20)
Distance from Camera (75, 150, 225)
Light(0/1)
Size of bottle (0, 1, 3)

kjetil b halvorsen
  • 1,206
  • 2
  • 18
  • 28
saimensis
  • 1
  • 1

1 Answers1

0

Using glmer should work. (lmer is only for linear mixed models, i.e. Gaussian responses.)

Detections_glmm <- glmer(Detection ~ Camera + (1|Day),    family="binomial")

If you really only have 3 days in your data set, you probably want to treat Day as a fixed rather than a random effect, see e.g. the GLMM FAQ or this CrossValidated question ...

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453