[R-sig-ME] specify random effects in lme4

Phillip Alday ph||||p@@|d@y @end|ng |rom mp|@n|
Sat Sep 28 20:58:12 CEST 2019


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:
> I would like to ask for your help in specifying the random effects of a
> model I have been working on in lme4. I have data from a field survey. The
> objective of the study is to relate wing size (respond variable) with
> habitat (exploratory variable, categorical variable with 2 levels). We
> performed a paired design by sampling 50 individuals of 3 species in a
> simple habitat and the same 3 species (n=50 again) in a complex habitat in
> a region. We replicated that in 20 regions. I am both interested in the
> species specific effects and community effects. For running the analyses
> per species is this model correct?
> 
> modela<-lmer(Wingsize~Habitat+(1|Region))
> 
> For community wise effects is this model correct?
> 
> modelb<-lmer(Wingsize~Habitat+(1|Region/Habitat/Species))
> 
> For a schematic check this
> https://stats.stackexchange.com/questions/419693/specify-random-effects-in-lme4
> 
> 
> Thank you in advance,
> 
> 
> Ben
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-mixed-models using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>



More information about the R-sig-mixed-models mailing list