[R] Lme4 and syntax of random factors

Ben Bolker bbolker at gmail.com
Tue Aug 13 15:55:37 CEST 2013


Robert U <tacsunday <at> yahoo.fr> writes:

> 
> Dear
> R-users,
> 

[snip]

  This question probably belongs on r-sig-mixed-models at r-project.org .
Followups there, please.

> Let's say that I have 2 random effects, A (e.g. species, k=2) and B
 (e.g. individuals, n=100). I made some research about model syntax,
 and I have the understanding that everything at the left side of the
 random œparameter is about SLOPE and everything at the right
 side about intercept :

  You really can't practically fit a random effect to 2 species (see 
http://glmm.wikidot.com/faq#fixed_vs_random
 
>  + (1 |B)
> would give me an intercept per individual.
  
>  + (1 |A)
> would give me an intercept per species.

  yes

>  + (1 |A:B)
> would give me an intercept per individuals with nested effect (individual
> inside species)

  This would be the same as (1|B) if the individuals are uniquely
identified.  Otherwise you probably want (1|A/B) [except that you
can't really fit a random effect for k=2, as discussed above]

>  I would like to have random slopes per species. So I thought I
> could do something like that :

  Probably not feasible.
 
>  + (A |B) so to have an intercept per individual and a slope value
> per species. Graphically, I would therefore obtain 100 lines with
> 100 different intercepts and 2 possible slopes (1 per
> species). However, when I extract random parameter values (ranef()),
> I have :

  what variable is your slope with respect to?  Suppose it's time.
Then I would recommend

 ~ A*time + (1|A:B)

which will fit a (FIXED effect) interaction between species and time
(different slopes and intercepts for each species), and a random
intercept per individual.



More information about the R-help mailing list