Skip to content
Prev 247098 / 398506 Next

GLMM with lme4 and octopus behaviour

Samaritan <d.harliwich <at> gmail.com> writes:
You might want to ask follow-up questions on the R-sig-mixed-models list
You say you want to use GLMM -- presumably awake is a binary variable
that you want to treat as such? If so, you need the argument
'family=binomial' in your model. (You might want to use the 'glmer'
function instead, for clarity, although in practice R takes care of
this for you.)
As a general practice you should probably code your data as
"deprived"/"allowed" rather than 0/1: you won't have to use as.factor
and you will automatically be able to keep track of the coding.

When I try to fit the model I get the following error
This is coming from inside lmer.  My guess is that you want
to make sure Time is a factor.

dat <- expand.grid(Time=1:5,Octopus=1:5)
dat$awake <- sample(0:1,prob=c(0.5,0.5),replace=TRUE,size=nrow(dat))

dat$Time <- factor(dat$Time)
dat$Octopus <- factor(dat$Octopus)

library(lme4)

lmer(awake~(1|Time/Octopus),data=dat)

  I got a similar error when both Time and Octopus were numeric.
When I turned one or the other but not both into a factor I got
different errors.  When they are both factors I get an error which
is related to the fact that I don't have enough data (only one
observation per block, so the block effects are confounded with
the residual variation)

lmer(awake~(1|Time)+(1|Octopus),data=dat)

which represents a crossed effect, does work.
Even though R is wonderful, if your supervisors use a different
statistical package, I would strongly recommend you stick to what 
they use so that you can get properly trained,  unless you are *very*
self-sufficient.