Re: [R] lmer and correlation

From: Douglas Bates <>
Date: Thu, 13 Mar 2008 13:33:47 -0500

On Thu, Mar 13, 2008 at 8:43 AM, R Help <> wrote:
> Hello list,
> I've been reading through the archives and it seems as though, as
> of right now, there is no way to specify the correlation structure in
> lmer. I was wondering if anyone knows if this is going to be
> implemented? I'm using mixed-effects models within a tree structure,
> so I make a lot of calls to lme to get the resulting deviance, and
> lmer2 is almost 5 times faster than lme on my test data, so if it may
> be implemented later I'd be willing to wait, otherwise I might look
> into trying to hack it myself.

I don't have any near-term plans for implementing a separate correlation argument for the lmer function so I would recommend that you hack it yourself.

I suggest starting with the development version of the lme4 sources, available at See the SCM tab for instructions on how to check out a read-only copy of the svn archive or go to the R Packages tag for a .tar.gz file of the current source package.

The way that Jose and I implemented correlation structures for the nlme package is to form a pre-whitened set of responses and the corresponding model matrices then use the standard lme representation on these pre-whitened components to optimize the log-likelihood with respect to the correlation parameters and the random effects parameters simultaneously.

You need to work out how to evaluate the log-likelihood (or, equivalently, the deviance) for the combined set of parameters. The slides at will give you some idea of what the slots in the "mer" class of objects in lme4 represent and how they are changed to accommodate changes in the model. Once the mer object is created most of the work is done in a set of C functions that are documented at Be aware that many of those functions are primarily for extensions to the linear mixed model, such as generalized linear mixed models and nonlinear mixed models and even generalized nonlinear mixed models. The ability to profile out the fixed-effects parameters in the case of linear mixed models provides a massive simplification in the computational approach and means that many of the more difficult steps for the other models can be skipped. Inside the mer_optimize function you will see that there is one path for linear mixed models and another path for everything else.

May I suggest that further discussion of this be moved to the list, which I have cc:'d on this reply? mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu 13 Mar 2008 - 18:42:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 13 Mar 2008 - 19:30:34 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive