I am analyzing data from a field experiment, and I am interested in the effects of fauna and altitude (fixed). Altitude has two levels, and at each site I have 5 blocks for the three levels of fauna (the blocks were set up to account for the heterogeneity in the soil). I guess that the model treating block as random, in lme4, would be:

lmer(response ~ altitude  + fauna + (1|block))

However, I replicated this study in 5 mountains. So can I treat mountain as another random factor and then:

lmer(response ~ altitude  + fauna + (1|block) + (1|mountain))

Or should I nest my blocks within mountains?

lmer(response ~ altitude  + fauna + (1|mountain:block))

I see people using nested designs when they have pseudoreplicates, but that is not my really my case as all my replicates are independent.

Here's how my data looks like:

mountain   altitude   treatment block response  
m1         high       t1        b1    124.77  
m1         high       t2        b1    55.77  
m1         high       t3        b1    88.99  
m1         high       t1        b2    88.99  
m1         high       t2        b2    88.99  
m1         high       t3        b2    88.99  
m1         low        t1        b6    124.77  
m1         low        t2        b6    55.77  
m1         low        t3        b6    78.99  
m1         low        t1        b7    89.99  
m1         low        t2        b7    33.99  
m1         low        t3        b7    22.87  

2 Answers 2


Since the blocks are explicitly nested, the random parts are (1|block) and (1|mountain).

altitude is a fixed term. If you want a single estimate for each level of altitude (except, of course, for the reference level), then just include altitude a single term as you did in your second suggestion above. However, you can let the effect of altitude vary between mountains, ie. a random slope model.

lmer(response ~ fauna + (1|block) + (altitude|mountain))

(You do not mention treatment, but it is part of your dataset so perhaps it should be in the model too?)

I think that a loglikelihood ratio test can be used to determine if the random slope model performs significantly better than the simpler model.


fm1 <- lmer(response ~ altitude + fauna + (1|block) + (1|mountain))
fm2 <- lmer(response ~ fauna + (1|block) + (altitude|mountain))
anova(fm1, fm2)
  • 1
    $\begingroup$ +1, but: while the likelihood ratio test can be used to test among models with different random effects, it is generally conservative (in the simplest case, p-values are twice as large as they should be -- see Pinheiro and Bates 2000, or discussion at glmm.wikidot.com/faq ...) $\endgroup$
    – Ben Bolker
    Dec 5, 2015 at 22:43

Since your blocks are nested within mountains, I would specify the random part of the model as (1|mountain) + (1|mountain:block) or (1|mountain/block), which is the same. That would allow you to quantify the variation a) among mountains and b) blocks within mountains.

EDIT: To address @BenBolker 's comment below: If your block within mountains are explicitly nested, that is, if you uniquely combined mountain with block in a variable say newblock, then (1|mountain) + (1|newblock) is also equivalent. See here for an example.

  • 2
    $\begingroup$ You might also comment that if the blocks are explicitly nested (i.e. uniquely labeled within mountains), then (1|mountain)+(1|block) is also equivalent, e.g. see stats.stackexchange.com/questions/67840/… $\endgroup$
    – Ben Bolker
    Nov 27, 2015 at 15:46
  • $\begingroup$ thanks a lot Stefan and @ben-bolker. Yes, the blocks are explicitly nested. However, I only want to account for a)variation among mountains and b) variation within blocks. Variation among blocks within mountain is in my fixed effect altitude. I'm sorry for not being more clear before. Can I use altitude as a fixed factor and as a nesting factor to nest blocks within? $\endgroup$ Nov 30, 2015 at 9:32
  • $\begingroup$ Hmmm, I am a bit confused now... a) if the blocks are explicitly nested (i.e. uniquely labelled within mountains), then there was no reason to specify (1|mountain:block) in your question, was it? b) When you say variation within blocks do you mean how block (i.e. soil heterogeneity) affects the variation of altitude and fauna within each block? c) How can variation among blocks within mountain be accounted for by your fixed effect altitude? It's probably best now when you provide a reproducible example in your question, see here. $\endgroup$
    – Stefan
    Nov 30, 2015 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.