[R-sig-eco] Indicating random effects in a mixed model with nesting and interaction

Kingsford Jones kingsfordjones at gmail.com
Mon Feb 23 22:06:22 CET 2009


On Mon, Feb 23, 2009 at 8:13 AM, Simon Power <simon.power at uct.ac.za> wrote:
> Hi
>
> My statistcal analysis is rather complicated. I have a situation where I have four factors, with one of the been nested into two of them and the one factor interacting with the rest as well the nested factor being random. This all results from a glasshouse pot experiment I conducted. I had two groups, "Legumes" and "Non-legumes", with each group containing three genera and each genus containing two species. Therefore there are three factors so far, Group, Genus and Species. Now species are nested within genus and group. The fourth factor is the treatment, all species were treated with two levels of phosphorus. In the analysis, phosphorus needs to interact with the other three factors. So what I have is design with both nested and factorial factors and I need the two to interact ( Biomass~(Group/Genus/Species)*Phosphorus).

Hi Simon,
Why do you need that interaction?  It would add 2*6*12*2 = 288 columns
to your design matrix, which is 4x the number of observations.


>  My problem is how to go about indicating that the Species factor, which is nested with genus and group is random. What package do I use (lme4) and how do I!
>  indicate the random effects with the interaction? Here is an example of my data set. Can anyone help?


There are a variety of ways to fit mixed models in R, and your options
are increased since you have a balanced, nested design.  If you use
lme4::lmer, random effects are enclosed in parentheses, with the type
of effects indicated on the left of the "|", and the grouping factor
on the right.

E.g.,

f1 <- lmer(Biomass ~ Phosphorus + (1|Species), data = yourdata)

has a fixed effect for treatment and predicts random intercepts for each species

or,

f2 <- lmer(Biomass ~ Phosphorus + (1|Group/Genus/Species), data=yourdata)

estimates the treatment effect and predicts random intercepts for
Group, Genus in Group, and Species in Genus in Group.

or

f3 <- lmer(Biomass ~ Phosphorus + (0+Phosphorus|Group/Genus/Species),
data=yourdata)

which is the same as the above model except now rather than an
intercept on the LHS of the "|" you are requesting prediction of
effects for each level of Phosphorus if it is a factor, or for random
slopes but no random intercepts if Phosphorus is considered continuous
(if you left out the "+ 0" it would estimate random slopes and
intercepts.

Note these aren't recommendations for analyzing your data -- just an
attempt to explain how random effects are specified in lmer formulas.

hoping it helps,

Kingsford Jones



>
>
>      Group Genus Species Phosphorus   Biomass
>      legume Aspalathus A.nivea 5 0.673609
>      legume Aspalathus A.nivea 5 0.550403
>      legume Aspalathus A.nivea 5 0.675882
>      legume Aspalathus A.nivea 50 1.142929
>      legume Aspalathus A.nivea 50 1.068928
>      legume Aspalathus A.nivea 50 1.113317
>      legume Aspalathus A.subtingens        5 0.105958
>      legume Aspalathus A.subtingens 5 0.693448
>      legume Aspalathus A.subtingens 5 0.176855
>      legume Aspalathus A.subtingens 50 0.819652
>      legume Aspalathus A.subtingens 50 0.878823
>      legume Aspalathus A.subtingens 50 0.739474
>      legume Cyclopia C.genistoides 5 0.261887
>      legume Cyclopia C.genistoides 5 0.14915
>      legume Cyclopia C.genistoides 5 -0.29405
>      legume Cyclopia C.genistoides 50 0.395505
>      legume Cyclopia C.genistoides 50 -0.06538
>      legume Cyclopia C.genistoides 50 0.227878
>      legume Cyclopia C.pubescens 5 -0.09903
>      legume Cyclopia C.pubescens 5 0.285057
>      legume Cyclopia C.pubescens 5 0.082526
>      legume Cyclopia C.pubescens 50 0.493785
>      legume Cyclopia C.pubescens 50 0.819986
>      legume Cyclopia C.pubescens 50 0.52278
>      legume Indigofera I.cytisoides 5 0.281444
>      legume Indigofera I.cytisoides 5 0.320145
>      legume Indigofera I.cytisoides 5 0.408235
>      legume Indigofera I.cytisoides 50 0.110623
>      legume Indigofera I.cytisoides 50 0.045725
>      legume Indigofera I.cytisoides 50 0.237567
>      legume Indigofera I.filifolia 5 0.754342
>      legume Indigofera I.filifolia 5 0.501069
>      legume Indigofera I.filifolia 5 0.675605
>      legume Indigofera I.filifolia 50 0.242735
>      legume Indigofera I.filifolia 50 0.470992
>      legume Indigofera I.filifolia 50 0.319055
>      Nonlegume  Elegia E.capensis 5 0.895721
>      Nonlegume     Elegia E.capensis 5 0.912309
>      Nonlegume Elegia E.capensis 5 0.782282
>      Nonlegume Elegia E.capensis 50 0.789401
>      Nonlegume Elegia E.capensis 50 0.685056
>      Nonlegume Elegia E.capensis 50 0.748347
>      Nonlegume Elegia E.persistens 5 -0.01635
>      Nonlegume Elegia E.persistens 5 0.217623
>      Nonlegume Elegia E.persistens 5 0.124578
>      Nonlegume Elegia E.persistens 50 0.109245
>      Nonlegume Elegia E.persistens 50 -0.02805
>      Nonlegume Elegia E.persistens 50 0.03836
>      Nonlegume Leucadendron    L.coniferum 5 0.552093
>      Nonlegume Leucadendron    L.coniferum 5 0.570604
>      Nonlegume Leucadendron    L.coniferum 5 0.509527
>      Nonlegume Leucadendron    L.coniferum 50 0.680958
>      Nonlegume Leucadendron    L.coniferum 50 0.457217
>      Nonlegume Leucadendron    L.coniferum 50 0.793007
>      Nonlegume Leucadendron    L.spissifolium 5 -0.03283
>      Nonlegume Leucadendron L.spissifolium 5 -0.04771
>      Nonlegume Leucadendron L.spissifolium 5 -0.01289
>      Nonlegume Leucadendron L.spissifolium 50 0.44862
>      Nonlegume Leucadendron L.spissifolium 50 0.42483
>      Nonlegume Leucadendron L.spissifolium 50 0.480291
>      Nonlegume Protea P.grandiceps 5 -0.24493
>      Nonlegume Protea P.grandiceps 5 -0.38648
>      Nonlegume Protea P.grandiceps 5 -0.2004
>      Nonlegume Protea P.grandiceps 50 -0.17161
>      Nonlegume Protea P.grandiceps 50 -0.07897
>      Nonlegume Protea P.grandiceps 50 -0.14574
>      Nonlegume Protea P.speciosa 5 0.447133
>      Nonlegume Protea P.speciosa 5 0.47613
>      Nonlegume Protea P.speciosa 5 0.412907
>      Nonlegume Protea P.speciosa 50 0.365221
>      Nonlegume Protea P.speciosa 50 0.517435
>      Nonlegume Protea P.speciosa 50 0.286728
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



More information about the R-sig-ecology mailing list