[R] Simple lme/lmer random effects questions

Brandon Invergo brandon at brandoninvergo.com
Mon Aug 11 22:43:42 CEST 2008


Hello,

I have two very rudimentary questions regarding the random effects terms 
in the lme and lmer functions. I apologize if this also partly strays 
into a general statistics question, but I'm a bit new to this all. So 
hopefully it'll be a quick problem to sort out...

Here is my experimental setup: I raised butterflies in 5 different 
testing chambers all set to different temperatures. Within the testing 
chambers, the butterflies were held in 10 different sleeves, which were 
rotated daily to compensate for microenvironmental effects. I measured 
several traits of the butterflies and I am constructing models for each 
trait (unfortunately, multivariate analysis isn't possible). In my 
models, sex and temperature are fixed factors and the sleeve is a random 
effect. Most of the response variables are normally distributed, but 
there is one with a Gamma distribution (time until an event) and another 
with poisson distribution (counts), so some models use lme while others 
use lmer. I would like to determine if, despite the daily rotation, 
there are still random effects from the individual sleeves. My two 
questions (assuming I haven't already made grave errors in my 
description of the setup) are:

1) In my data file, the "sleeve" variable is just marked with a number 1 
through 10; the temperature is noted in a different column, so the 50 
sleeves do not have unique names, but rather there are 5 instances of 
each of the 10 sleeve numbers. If sleeve is to be properly included in 
the models as a random effect, is it sufficient to leave the values as 
they are or should I generate unique names for all combinations of 
sleeve number and temperature, using something like
 > data$sleeve.in.temp <- factor(with(data, temp:sleeve)[drop=TRUE])

2) (this is the one that strays more into standard statistics territory, 
sorry) I'm a bit confused on how to actually set up the random effects 
term for the models. Given my experimental setup, using the lme syntax, 
should it be:
 > model <- lme(response ~ sex*temp, random=~temp|sleeve, data)
or
 > model <- lme(response ~ sex*temp, random=~1|sleeve, data)
or something else? I've searched and searched, but everything I find 
online seems to be significantly more advanced than what I'm doing, 
leaving me even more confused than when I started!


Thank you very much for your help!! I want to be sure I do this analysis 
right....
Cheers,
-brandon



More information about the R-help mailing list