[R-sig-ME] Modeling correlation structure in mixed models

Kingsford Jones kingsfordjones at gmail.com
Sat Jun 27 04:48:16 CEST 2009

Hi Phillip,

Welcome.  Although I'm a fan of PROC MIXED, I think you'll find doing
your mixed modeling in R a relative joy.  Unfortunately, to experience
the joy one must learn to navigate the byzantine labyrinth of
documentation that has grown from this community effort.  A few leads
are offered below...

On Fri, Jun 26, 2009 at 4:42 PM, Phillip
Chapman<pchapman at stat.colostate.edu> wrote:
> Hi All,
> I have been trying to learn mixed models in R by reading the books by
> Pinheiro and Bates; Faraway (both linear models books); and Crawley (R
> Book), but I would appreciate some guidance from the more experience R
> users. (I have a fair amount of experience with mixed models in SAS.)
> 1. Is there another (other than the above) suggested reference for
> understanding the workings of the nlme and lme4 libraries?

P&B is of course the authoritative reference for the nlme package, and
Doug has mentioned on this list that in his (limited) spare time he is
working on a book to accompany lme4.  The lme4 package does come with
several vignettes that can be accessed from R by a call to the
vignette function or by simply opening the pdfs in
yourRlibrary/lme4/doc/.  There is also a vignette in the SASmixed
package called 'lmer for SAS PROC MIXED Users'.  Other helpful
references can be found on the CRAN contributed documentation section,
such as the Mixed Models Web Appendix to John Fox's book.  I haven't
read Gelman and Hill's Data Analysis and Regression using
Multilevel/Hierarchical models, but as I understand it they user lmer
extensively, with wrappers for Bayesian inferences.  Also, Harald
Baayen has a freely available draft of a book on analyzing linguistic
data that includes many lmer examples:

Googling the following may also be useful:
lmer filetype:pdf

Here are some of Doug's documents that show up:


> 2. Is it the case that lme accepts correlated structures ONLY in the error
> term? I have problems in which I would like model random effects (such as
> year) using a random term with an autocorrelated structure. In SAS I use
> options to the “repeated” statement to add correlation structure to the
> error term, and I use options to the “random” statement to give correlation
> structure to the other random effects. I haven’t found anything in lme or
> lmer that allows me to specify correlated random effects. gee only allows
> correlation structure in the error term and does not allow random effects.

This is something that I have wondered about as well -- as far as I
know one can only specify a correlation structure for the error
covariance matrix, and only using the nlme package (not lme4).
However, given that there are thousands of R packages available I
would not be surprised if someone's already coded up a way to do this
(perhaps in one of the spatial packages using a Bayesian approach,
such as spBayes or geoRglm?)

> 3. All of the examples of random effects in lme seem to have nested error
> structures. Is it the case that lme does not allow crossed random effects?
> lmer allows much more flexible specification of random effects, but I don’t
> see anything that allows correlated error structures.

Although nlme is designed for nested data, crossed random effects can
be specified using a combination of pdBlocked and pdIdent objects (see
page 163 of P&B).  However it's an awkward specification and the
fitting can be slow (IIRC). On the other hand lmer offers elegant
methods of specifying crossed models and speedy methods for fitting

> Thanks in advance,

You're welcome -- hope it helped,

Kingsford Jones

> Phil Chapman
> _______________________________________________
> 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