Specifying random effects in lme()
On Wed, 2007-05-09 at 16:05 +0100, Mike Dunbar wrote:
Gav I don't know the answer to your question, but it may not be possible. If it is possible to specify it, then you may still run into problems fitting it. You're trying to fit quite a complex model here with two random slopes and an AR term, are you really sure your model needs to be that complicated?
Hi Mike, That's one of the things we want to test. The random effects just take up an extra df or eleven. I have plenty to spare in the model, with many years data. For the extra 22 df used up, does the model fit significantly better using AIC/BIC and friends? I can fit the model in lmer very easily, converges nicely and quickly. But I wanted to have the AR1 term in there to mop up some of the residual autocorrelation in the error structure. There is some indication of autocorrelation in the residuals, and testing models without the AR term and with the AR show that the model with the AR term is a big improvement as measured by AIC, BIC and the likelihood ratio test. There is some evidence that the effects of the two covariates does differ amongst sites based on analysis of the model output from the model with only random intercepts. We'd like to test if the more complex model fits the data better. Cheers Mike, G
Can you fit the lmer model you mention? If so, is there evidence for autocorrelation of residuals? cheers Mike
Gavin Simpson <gavin.simpson at ucl.ac.uk> 09/05/2007 14:23 >>>
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,
Gav
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
_______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% 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 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%