Solved – Crossed & nested random effects in lmer

I'm trying to get the specification correct for a crossed and nested effect model. Suppose I want to cross Sample & typeStatus, and then have a random effect of day nested within that cross?

I've been trying to figure it out from Ch2 (pdf) of the online book, lme4: Mixed-effects Modeling with R, but can't quite seem to get it.

The pdf lists an example of fitting a model with crossed random effects using the Penicillin dataset in section 2.1.2 (p. 4 of pdf), and an example of fitting a model with nested random effects using the Pastes dataset in section 2.2.2 (p. 14 of pdf). At the beginning of the latter section, it reads:

Fitting a model with simple, scalar random effects for nested factors is done in exactly the same way as fitting a model with random effects for crossed grouping factors.

I don't know much about your data, but from these I would guess that you might specify your model like so:

library(lme4) model = lmer(y ~ 1 + covariates + (1|Sample) + (1|typeStatus) + (1|day), data=myData)   

Similar Posts:

Rate this post

Leave a Comment