[R-sig-ME] Specifying random effects in lme()

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed May 9 15:23:47 CEST 2007

Dear List,

I am modelling repeated measures data from 11 sites in the UK using
lme() from the nlme package. I have the following call for a random
intercept model with an AR1 error structure:

mod <- lme(doc ~ temp + log.so4 + log.cl, random = ~ 1 | site,
           correlation = corAR1(), data = hydro)

I would like to fit a model that has random effects for log.so4 and
log.cl within site, so that I am fitting a random slop and intercept
model --- we want the effect of log.so4 and log.cl to vary between sites
and to compare the fits of the two models.

If I am following lmer() in lme4 correctly, I believe I could fit this
model as:

hydro.lmer <- lmer(doc ~ temp + log.so4 + log.cl +
                   (log.so4 | site) + (log.cl | site),
                   data = hydro)

but without the AR1 correlation.

I am struggling to get the syntax correct for random in lme() to add
random effects to log.so4 and log.cl. I have only managed to get a model
where one of the coefficients (log.cl) also has a random effect.

I would be most grateful if someone could explain how to fit the model
in lme() by showing me the correct form for the random argument.

Many thanks,


 Gavin Simpson                 [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk

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