[R-sig-ME] How to specify the random effects in 'lme' function

Ben Bolker bbolker at gmail.com
Thu Sep 29 17:07:50 CEST 2011


Jackie Jia Zhou <dr.jzhou at ...> writes:

[snip]

> I have some questions about how to specify the random effects in the 'lme'
> function. My sample data is as below:
> 
> # Data name: collection
> 
> SampleID     Batch       value        Age
> A1                batch1      0.898      32
> A2                batch1      0.987      30
[snip]
> .                     .                .            .
> D9                batch4       0.678      20
> D10              batch4       0.768      16
> 
> I want to see if the 'value' is associated with Age, and 'inter-individual
> variation (SampleID)' and 'batch effects (Batch)' will be treated as random
> effects. However, I don't know how to specify the random effects part.
> 
> My sample code:
> 
> fm <- lme(value~Age, random=~1|SampleID + Batch, na.action=na.omit,
> data=collection)

[snip]

  I think you want random=~1|Batch/SampleID . In this case
SampleID is "explicitly" nested, i.e. the individual identifiers
are all unique (rather than being labelled e.g. 1, 2, 3, ... 1, 2, 3, ...,
1, 2, 3, ...) but I believe that lme can handle this fine.
After you run the model, check the summary for the reported numbers
of units within grouping levels to make sure it makes sense.




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