help with a cross-classified random effects model code in R.
On Wed, Sep 3, 2008 at 7:14 AM, Stijn Ruiter <s.ruiter at maw.ru.nl> wrote:
Dear Dr. Bates, You replied to a question by Violet(Shu) Xu on how to estimate cross-classified (XC) models. In the DIGEST version however, no example code is provided. In general, how do we estimate XC models using lme4?
Is the following example for a null model for some dependent variable Y for pupils who attended specific primary and secondary schools correct? Or does lmer then estimate a nested model?
lmer(Y~(1|primaryschool)+(1|secondaryschool),data=dataname)
That will estimate the model with crossed random effects. An example of exactly this type is
data(ScotsSec, package = "mlmRev") library(lme4)
Loading required package: Matrix Loading required package: lattice Attaching package: 'Matrix' The following object(s) are masked from package:stats : xtabs
(fm1 <- lmer(attain ~ (1|primary) + (1|second), ScotsSec))
Linear mixed model fit by REML
Formula: attain ~ (1 | primary) + (1 | second)
Data: ScotsSec
AIC BIC logLik deviance REMLdev
17159 17183 -8575 17149 17151
Random effects:
Groups Name Variance Std.Dev.
primary (Intercept) 1.13002 1.0630
second (Intercept) 0.37222 0.6101
Residual 8.11069 2.8479
Number of obs: 3435, groups: primary, 148; second, 19
Fixed effects:
Estimate Std. Error t value
(Intercept) 5.5017 0.1787 30.79
To see that the primary and secondary schools classifications are not
nested you can check the image of the cross classification of those
factors produced by
image(xtabs(~ primary + second, ScotsSec, sparse = TRUE))
I enclose a PDF file of that image.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ScotsSec.pdf
Type: application/pdf
Size: 59109 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20080903/14fce9d1/attachment.pdf>