[R-sig-ME] nested random factor

Ben Bolker bbolker at gmail.com
Wed Mar 19 15:57:50 CET 2014


On 14-03-19 10:46 AM, Seth Bigelow wrote:
> Well -- I don't know about the 'correct' model, but you might consider two
> ideas. First, the variance among samples might differ according to location.
> If so, you would get a better model by nesting sample within location, e.g.,
> using the statement (1|location/sample), rather than (1|location) +
> (1|sample). You can test whether this model is better with likelihood ratio
> tests, i.e., anova(UnNestedmodel,NestedModel).

  (1|location/sample) is equivalent to (1|location)+(1|location:sample).
 If the samples are uniquely labeled (e.g. A1, A2, A3, B1, B2, B3, ...
rather than 1, 2, 3, 1, 2, 3,) then these are *also* equivalent to
(1|location)+(1|sample).  If they are not uniquely labeled then
(1|location)+(1|sample) represents crossed random effects, which you
probably *don't* want unless there is something that makes the first
sample in every location the same.  (lme can't do crossed random effects
in this way.)

> 
> Second, you probably want to account for serial autocorrelation in samples
> taken from the same location, repeatedly over time -- i.e. in the 'week'
> variable. I've done this in SAS but never mastered the syntax in nlme/lme4.

  lme4 can't do this, you would need lme with e.g.
correlation=corAR1(formula=~week), although the uneven sampling of weeks
could be problematic.

> 
> Good luck
> -Seth 
> 
> 
> 
> -----Original Message-----
> From: r-sig-mixed-models-bounces at r-project.org
> [mailto:r-sig-mixed-models-bounces at r-project.org] On Behalf Of sandrine le
> squin
> Sent: Wednesday, March 19, 2014 3:01 AM
> To: r-sig-mixed-models at r-project.org
> Subject: [R-sig-ME] nested random factor
> 
> Dear all,
> 
> I'm using lmer from lme4 package but I am not sure of what I'm doing.
> 
> The dataset has the following variables :
> - Treatment (fixed, 3 levels)
> - Location (fixed, 4 levels)
> - Sample (random, 5 levels). 5 samples are taken in each location (randomly)
> - Subsample (random, 3 levels). 3 subsamples are taken in each sample. One
> treatment is assigned (randomly) to one of the subsample.
> 
> The study was conducted every Wednesday during 15 weeks in 2013, from week
> 32 to week 47 (no observations for week 33).
> 
> For the first location, samples are taken weeks 32, 36, 39, 42 and 49.
> For the second location, samples are taken the week 46.
> For the third location, samples are taken weeks 35, 38, 41 and 44.
> For the 4th location, samples are taken week 34, 37, 40, 43, 47.
> 
> For each location* i*, week *j(i)*, sample* k(ij)* and treatment *l*, the
> "richness in sugar" of each subsample has been recorded.
> The aim of the study is to see if there is an effect of the factor
> "treatment" on the response "richness".
> 
> I am new in mixed model so I did some research but I am a little bit
> confused with the sampling design.
> 
> I consider "location", "week" and "sample" as random factor, with sample
> nested in week nested in location.
> To avoid implicitly nested representations, "sample" has been recoded
> (factor with 75 levels (5 samples*15 weeks)).
> 
> I write in R:
> lmer(richness ~ treatment + (1|location) + (1|week) + (1|sample), data =
> mydata)

  You said above the location and treatment are fixed: did you mean
location was random?

  I would use

 richness ~ treatment + (1|location/week/sample)

since within any given week samples are only taken in one location.

4 levels for location is a little low for reliable estimation of random
effects, so you might consider

 Since the treatments are replicated within locations, weeks,
treatments, etc., you might need to consider
(treatment|location/week/sample), although that might be overfitting the
model ...


> 
> Is my model correct ?
> 
> Thank you for your help
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> 
> _______________________________________________
> R-sig-mixed-models at 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