UCLA Academic Technology Services HomeServicesClassesContactJobs
Help the Stat Consulting Group by giving a gift             
Loading

R Textbook Examples
Multilevel Analysis Techniques and Applications by Joop Hox
Chapter 7: Cross-Classified Multilevel Models


Table 7.1 on page 126 using the pupcross dataset.

Part 1: Intercept only.

library(foreign)
library(lme4)

pupcross<-read.dta("http://www.ats.ucla.edu/stat/stata/examples/mlm_ma_hox/pupcross.dta")

m1<-lmer(achiev ~ (1|sschool) + (1|pschool), pupcross, REML=FALSE)
summary(m1)

Linear mixed model fit by maximum likelihood 
Formula: achiev ~ (1 | sschool) + (1 | pschool) 
   Data: pupcross 
  AIC  BIC logLik deviance REMLdev
 2326 2345  -1159     2318    2321
Random effects:
 Groups   Name        Variance Std.Dev.
 pschool  (Intercept) 0.169348 0.41152 
 sschool  (Intercept) 0.065401 0.25574 
 Residual             0.513169 0.71636 
Number of obs: 1000, groups: pschool, 50; sschool, 30

Fixed effects:
            Estimate Std. Error t value
(Intercept)  6.34865    0.07831   81.07

Part 2: intercept plus pupil level variables

m2<-lmer(achiev ~ pupsex + pupses +(1|sschool) + (1|pschool), pupcross, REML=FALSE)
summary(m2)

Linear mixed model fit by maximum likelihood 
Formula: achiev ~ pupsex + pupses + (1 | sschool) + (1 | pschool) 
   Data: pupcross 
  AIC  BIC logLik deviance REMLdev
 2255 2285  -1122     2243    2258
Random effects:
 Groups   Name        Variance Std.Dev.
 pschool  (Intercept) 0.169009 0.41111 
 sschool  (Intercept) 0.063606 0.25220 
 Residual             0.474255 0.68866 
Number of obs: 1000, groups: pschool, 50; sschool, 30

Fixed effects:
            Estimate Std. Error t value
(Intercept)  5.75548    0.10527   54.67
pupsexgirl   0.26131    0.04564    5.73
pupses       0.11409    0.01610    7.09

Correlation of Fixed Effects:
           (Intr) ppsxgr
pupsexgirl -0.254       
pupses     -0.643  0.075

Part 3:  primary by secondary School crossed with pupil and school variables

m3<-lmer(achiev ~ pupsex  + pupses + pdenom + sdenom +(1|sschool) + (1|pschool), pupcross, REML=FALSE)
summary(m3)

Linear mixed model fit by maximum likelihood 
Formula: achiev ~ pupsex + pupses + pdenom + sdenom + (1 | sschool) +      (1 | pschool) 
   Data: pupcross 
  AIC  BIC logLik deviance REMLdev
 2253 2293  -1119     2237    2257
Random effects:
 Groups   Name        Variance Std.Dev.
 pschool  (Intercept) 0.159410 0.39926 
 sschool  (Intercept) 0.055424 0.23542 
 Residual             0.474105 0.68855 
Number of obs: 1000, groups: pschool, 50; sschool, 30

Fixed effects:
            Estimate Std. Error t value
(Intercept)  5.51850    0.14077   39.20
pupsexgirl   0.26308    0.04561    5.77
pupses       0.11356    0.01609    7.06
pdenomyes    0.20412    0.12410    1.64
sdenomyes    0.17615    0.09465    1.86

Correlation of Fixed Effects:
           (Intr) ppsxgr pupses pdnmys
pupsexgirl -0.203                     
pupses     -0.472  0.075              
pdenomyes  -0.524  0.021  0.004       
sdenomyes  -0.428  0.003 -0.025 -0.014

Part 4:  primary by secondary School crossed with pupil and school variables with variable pupses being modeled as a random effect.

m4<-lmer(achiev ~ pupsex  + pupses + pdenom + sdenom +(1|sschool) 
                  + (1|pschool) + (pupses|pschool), pupcross, REML=FALSE)
summary(m4)

Linear mixed model fit by maximum likelihood 
Formula: achiev ~ pupsex + pupses + pdenom + sdenom + (1 | sschool) +      (1 | pschool) + (pupses | pschool) 
   Data: pupcross 
  AIC  BIC logLik deviance REMLdev
 2246 2300  -1112     2224    2244
Random effects:
 Groups   Name        Variance  Std.Dev. Corr   
 pschool  (Intercept) 0.0950452 0.308294        
          pupses      0.0080183 0.089545 -0.565 
 pschool  (Intercept) 0.0535395 0.231386        
 sschool  (Intercept) 0.0537343 0.231807        
 Residual             0.4583575 0.677021        
Number of obs: 1000, groups: pschool, 50; sschool, 30

Fixed effects:
            Estimate Std. Error t value
(Intercept)  5.53241    0.13746   40.25
pupsexgirl   0.25316    0.04530    5.59
pupses       0.11423    0.02047    5.58
pdenomyes    0.19990    0.11764    1.70
sdenomyes    0.16456    0.09343    1.76

Correlation of Fixed Effects:
           (Intr) ppsxgr pupses pdnmys
pupsexgirl -0.209                     
pupses     -0.491  0.056              
pdenomyes  -0.512  0.029  0.006       
sdenomyes  -0.432  0.006 -0.020 -0.017

How to cite this page

Report an error on this page or leave a comment

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California