Skip to content
Prev 17950 / 20628 Next

specify random effects in lme4

The decision to include a variable as a fixed or random effect doesn't
depend on whether or not that variable is a nuisance / control variable.
That's a common but really misleading heuristic.

Random effects estimate variance and estimating the variance of
something with only 3 instances (e.g. species in your design) doesn't
really make that much sense.

For your second model, see Thierry Onkelinx's many comments on this
mailing list about having the same variable as a fixed and random effect
as well as his blog post:
https://www.muscardinus.be/2017/08/fixed-and-random/ .

All that said,  you could run different models by species:

lmer(Wingsize ~ 1 + Habitat + (1|Region)) for each species

Or you could do some fun nesting of the fixed effects and have a single
model that estimates all these effects within each species:

lmer(Wingsize ~ 1 + Species/Habitat + (1|Region))

The model

lmer(Wingsize ~ 1 + Habitat + (1|Region/Species))

which expands to

lmer(Wingsize ~ 1 + Habitat + (1|Region) + (1|Region:Species)

is technically valid model, but it treats the same species occurring in
different regions as being different entities.  Whether or not that's
desirable for your work is something you have to know based on your own
research question and domain-specific knowledge.

The model

lmer(Wingsize~Habitat+(1|Region/Habitat))

expands to

lmer(Wingsize~Habitat+(1|Region) + (1|Region:Habitat))

which actually a special case of

lmer(Wingsize~Habitat+(0 + Habitat|Region)

when the variance-covariance matrix for the random effects is compound
symmetric.

This is rapidly getting into quite advanced applications, but if you
combine the last two Region/Species and Region/Habitat bits, then you
understand a bit more about how the three-level nesting
Region/Habitat/Species will be handled. My tendency would be to leave
habitat on the left-hand side of the | and then think about whether you
want Species/Habitat in the fixed effects or Habitat/Species as a
grouping variable (based on the considerations above).

Best,

Phillip
On 01/08/2019 16:47, Ben Adams wrote: