Mixed Effects Model – How to Handle Nested Data with Mixed Effects Model in R

lme4-nlmemixed modelmodelnested datar

I have data collected from an experiment organized as follows:

Two sites, each with 30 trees. 15 are treated, 15 are control at each site. From each tree, we sample three pieces of the stem, and three pieces of the roots, so 6 level 1 samples per tree which is represented by one of two factor levels (root, stem). Then, from those stem / root samples, we take two samples by dissecting different tissues within the sample, which is represented by one of two factor levels for tissue type (tissue type A, tissue type B). These samples are measured as a continuous variable. Total number of observations is 720; 2 sites * 30 trees * (three stem samples + three root samples) * (one tissue A sample + one tissue B sample). Data looks like this…

        ï..Site Tree Treatment Organ Sample Tissue Total_Length
    1        L  LT1         T     R      1 Phloem           30
    2        L  LT1         T     R      1  Xylem           28
    3        L  LT1         T     R      2 Phloem           46
    4        L  LT1         T     R      2  Xylem           38
    5        L  LT1         T     R      3 Phloem          103
    6        L  LT1         T     R      3  Xylem           53
    7        L  LT1         T     S      1 Phloem           29
    8        L  LT1         T     S      1  Xylem           21
    9        L  LT1         T     S      2 Phloem           56
    10       L  LT1         T     S      2  Xylem           49
    11       L  LT1         T     S      3 Phloem           41
    12       L  LT1         T     S      3  Xylem           30

I am attempting to fit a mixed effects model using R and lme4, but am new to mixed models. I'd like to model the response as the Treatment + Level 1 Factor (stem, root) + Level 2 Factor (tissue A, tissue B), with random effects for the specific samples nested within the two levels.

In R, I am doing this using lmer, as follows

fit <- lmer(Response ~ Treatment + Organ + Tissue + (1|Tree/Organ/Sample)) 

From my understanding (…which is not certain, and why I am posting!) the term:

(1|Tree/Organ/Sample)

Specifies that 'Sample' is nested within the organ samples, which is nested within the tree. Is this sort of nesting relevant / valid? Sorry if this question is not clear, if so, please specify where I can elaborate.

Best Answer

I think this is correct.

  • (1|Tree/Organ/Sample) expands to/is equivalent to (1|Tree)+(1|Tree:Organ)+(1|Tree:Organ:Sample) (where : denotes an interaction).
  • The fixed factors Treatment, Organ and Tissue automatically get handled at the correct level.
  • You should probably include Site as a fixed effect (conceptually it's a random effect, but it's not practical to try to estimate among-site variance with only two sites); this will reduce the among-tree variance slightly.
  • You should probably include all the data within a data frame, and pass this explicitly to lmer via a data=my.data.frame argument.

You may find the glmm FAQ helpful (it's focused on GLMMs but does have stuff relevant to linear mixed models as well).