# Nested random effects and interaction terms in lme4

I have a data set containing various vegetation and geomorphic variables sampled in 3 distances on both sides of 43 drainage ditches (Location). Roughly half of these ditches are occupied by a beaver, the other half is empty. Now I want to run a model with the binomial response variable Status ("beaver == 1" / "beaver == 0")

I'm struggling with the order and layout of the nested and interaction effects using glmer. So far I've got

fit <- glmer(Status ~ BankslopeScaled + Connectivity +
Canal_width + Distance:Food_crops +
Distance:Edible_trees +
(1 | Distance/Side/Location),


but I'm not sure if I still have pseudoreplication in my data or whether I correctly applied the formula in order to estimate the influence of the predictors in every distance on both sides in each Location.

Like, if food_crops in the 3rd distance on the left side is lower than edible_trees in the 2nd distance on the right side, then ...

I feel like there's something wrong with my random effects-term.

My output looks like this:

summary(fit)

Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: binomial  ( logit )
Formula: Status ~ BankslopeScaled + Connectivity + Canal_width + Distance:Food_crops +
Distance:Edible_trees + (1 | Distance/Side/Location)
Data: Satz

AIC      BIC   logLik deviance df.resid
314.6    360.8   -144.3    288.6      245

Scaled residuals:
Min       1Q   Median       3Q      Max
-2.18541 -0.71205  0.07243  0.82483  1.75303

Random effects:
Groups                   Name        Variance  Std.Dev.
Location:(Side:Distance) (Intercept) 2.834e-02 1.683e-01
Side:Distance            (Intercept) 2.074e-10 1.440e-05
Distance                 (Intercept) 2.085e-10 1.444e-05
Number of obs: 258, groups:  Location:(Side:Distance), 258; Side:Distance, 6; Distance, 3

Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept)            -2.86517    0.79747  -3.593 0.000327 ***
BankslopeScaled         1.76475    0.62541   2.822 0.004776 **
Connectivity            0.10394    0.02729   3.809 0.000140 ***
Canal_width             0.19138    0.11089   1.726 0.084364 .
Distance1:Food_crops    0.03667    0.09366   0.391 0.695441
Distance2:Food_crops    0.10852    0.08996   1.206 0.227694
Distance3:Food_crops    0.06303    0.08502   0.741 0.458510
Distance1:Edible_trees  0.02273    0.01327   1.712 0.086818 .
Distance2:Edible_trees -0.01750    0.02992  -0.585 0.558738
Distance3:Edible_trees  0.09769    0.07986   1.223 0.221201
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

[correlation of fixed effects snipped]


A point into the right direction is much appreciated!

• You probably shouldn't treat Distance as a random effect in any case (estimates of random effects with only 3 levels are very unreliable)
• You already implicitly have the main effects of Distance in your model through the Distance:Food_crops and Distance:Edible_trees interactions.
• ... for both these reasons, you should leave Distance out of your random-effects specification: (1 | Distance:Side) + (1 | Distance:Side:Location) should work to include the two lower nested levels.
• you will still probably find that the (1|Distance:Side) random effect has variance of effectively zero ... but you might as well leave it in.
• Tanks a lot!! The random effect variance of (1|Distance:Side) is indeed actually zero. And so is is (1|Distance:Side:Location). That's peculiar... And another thing came to my mind: Most of the time, Edible_trees and Food_crops and other variables differed hugely on both Sides of one Location, regardless of their apparant promximity to each other. So, Side does not necessarily have to be included as a random effect after all, although I feel I somehow should tell the model that there are 2 Sides in each Location. Is there a possibility to account for that? Thanks again. – Ruben Apr 6 '15 at 9:37
• edit: Side should not be a random effect anyways. I just have to weave that in somehow. – Ruben Apr 6 '15 at 12:24