1 Problem

Understand the meaning of predictors at different levels as well as the effect of the centering the teacher level predictor against the respective school-level means in a school-teacher-pupil three-level example

# path to working directory
setwd("C:/Users/openw/Documents")
# package management
library(pacman)
# load them
pacman::p_load(mlmRev, tidyverse, lme4, merTools)
# input data
dta <- read.csv("C:/Users/openw/Documents/pts.csv")
#
head(dta)
##   School Teacher Pupil      Read_0 Read_1
## 1      1      11    18 -0.16407000 4.2426
## 2      1      11    19 -0.98126000 1.0000
## 3      1      11    20 -1.25370000 2.2361
## 4      1      11    15 -0.87230000 3.1623
## 5      1      11    17 -0.00063104 3.4641
## 6      1      11    16 -0.92678000 4.0000
# coerce variables to factor type and
# compute mean Read_0 by school
dta <- dta %>%
  mutate(School = factor(School), Teacher = factor(Teacher),
         Pupil = factor(Pupil)) %>%
  group_by(School) %>%
  mutate(msRead_0 = mean(Read_0))
#
# compute mean Read_0 by teacher and
# centered teacher mean of Read_0 (from respective school means)
#
dta <- dta %>%
  group_by(Teacher) %>%
  mutate(mtRead_0 = mean(Read_0), ctRead_0 = mean(Read_0) - msRead_0 )

##
# no predictor
summary(m0 <- lmer(Read_1 ~  (1 | School) + (1 | Teacher), data = dta))
## Linear mixed model fit by REML ['lmerMod']
## Formula: Read_1 ~ (1 | School) + (1 | Teacher)
##    Data: dta
## 
## REML criterion at convergence: 2486.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -3.05438 -0.65686  0.06497  0.62523  2.47233 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Teacher  (Intercept) 0.1370   0.3701  
##  School   (Intercept) 0.1277   0.3574  
##  Residual             1.3250   1.1511  
## Number of obs: 777, groups:  Teacher, 46; School, 20
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)   3.3755     0.1065   31.69

The estimated reading attainment at the end of year one is 3.375 and the variances are 0.137, 0.128 and 1.325 at the teacher, school and observation levels.

Most of the variance comes from the measurements (within the same teacher), whereas the variance in the teacher level is greater than that at the school level. These results indicate fairly significant variation in reading attainment at the end of year among teacher and in mean reading attainment among schools.

# add a school-level predictor
summary(m0_s <- update(m0, . ~ . + msRead_0))
## boundary (singular) fit: see help('isSingular')
## Linear mixed model fit by REML ['lmerMod']
## Formula: Read_1 ~ (1 | School) + (1 | Teacher) + msRead_0
##    Data: dta
## 
## REML criterion at convergence: 2467.4
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -3.06110 -0.65597  0.06822  0.62772  2.45391 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Teacher  (Intercept) 0.1234   0.3513  
##  School   (Intercept) 0.0000   0.0000  
##  Residual             1.3224   1.1500  
## Number of obs: 777, groups:  Teacher, 46; School, 20
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  3.39822    0.06808  49.918
## msRead_0     1.00159    0.17807   5.625
## 
## Correlation of Fixed Effects:
##          (Intr)
## msRead_0 0.086 
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

The estimated reading attainment at the end of year one is 3.3982 and the variances are 0.123, 0 and 1.322 at the teacher, school and observation levels.

Most of the variance comes from the measurements (within the same teacher), whereas the variance in the teacher level is greater than that at the school level. These results indicate fairly significant variation in reading attainment at the end of year among teacher and in mean reading attainment among schools.

0.1234 + 0 + 1.3224 = 1.4458

0.1237/1.4458 = 0.0856

0/1.4458 = 0

(0.0856 + 0)/1.4458 ≈ 0.059

The similarity with respect to reading scores at year one of the same school and teacher controlling for scores at reception is about 6%.

(0.1370+0.1277 - (0.1234 + 0))/0.2647 = 0.5338

About 53% of variation of scores at year 1 between teacher and school can be attributed to their mean reading attainment scores at reception at school level.

# add a teacher-level predictor
summary(m0_t <- update(m0, . ~ . + mtRead_0))
## boundary (singular) fit: see help('isSingular')
## Linear mixed model fit by REML ['lmerMod']
## Formula: Read_1 ~ (1 | School) + (1 | Teacher) + mtRead_0
##    Data: dta
## 
## REML criterion at convergence: 2434.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -3.07539 -0.65979  0.06707  0.63259  2.49973 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. 
##  Teacher  (Intercept) 3.296e-15 5.741e-08
##  School   (Intercept) 4.471e-02 2.114e-01
##  Residual             1.309e+00 1.144e+00
## Number of obs: 777, groups:  Teacher, 46; School, 20
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  3.40649    0.06307  54.010
## mtRead_0     1.07319    0.11495   9.336
## 
## Correlation of Fixed Effects:
##          (Intr)
## mtRead_0 0.024 
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

The estimated reading attainment at the end of year one is 3.4065 and the variances are 3.30e-15, 4.47e-02 and 1.31e+00 at the teacher, school and observation levels.

Most of the variance comes from the measurements (within the same teacher), whereas the variance in the teacher level is greater than that at the school level. These results indicate fairly don’t significant variation in reading attainment at the end of year among teacher and in mean reading attainment among schools.

3.30e-15 + 4.47e-02 + 1.31e+00 = 1.3547

3.30e-15/1.3547 = 2.4359637e-15

4.47e-02/1.3547 = 0.033

(2.4359637e-15 + 0.033)/1.3547 ≈ 0.024

The similarity with respect to reading scores at year one of same school and teacher controlling for scores at reception is about 2%.

(0.1370+0.1277 - (3.30e-15 + 4.47e-02))/0.2647 = 0.83

About 83% of variation of scores at year 1 between teacher and school can be attributed to their mean reading attainment scores at reception at teacher level.

# add a teacher-level predictor away from respective school means
summary(m0_ct <- update(m0, . ~ . + ctRead_0))
## boundary (singular) fit: see help('isSingular')
## Linear mixed model fit by REML ['lmerMod']
## Formula: Read_1 ~ (1 | School) + (1 | Teacher) + ctRead_0
##    Data: dta
## 
## REML criterion at convergence: 2454.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1804 -0.6461  0.0791  0.6420  2.5272 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. 
##  Teacher  (Intercept) 2.462e-10 1.569e-05
##  School   (Intercept) 1.764e-01 4.200e-01
##  Residual             1.311e+00 1.145e+00
## Number of obs: 777, groups:  Teacher, 46; School, 20
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)   3.3896     0.1029  32.932
## ctRead_0      1.1742     0.1581   7.427
## 
## Correlation of Fixed Effects:
##          (Intr)
## ctRead_0 0.000 
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

The estimated reading attainment at the end of year one is 3.3896 and the variances are 2.462e-10, 1.764e-01 and 1.311e+00 at the teacher, school and observation levels.

Most of the variance comes from the measurements (within the residual), whereas the variance in the teacher level is smaller than that at the school level. These results indicate fairly significant variation in reading attainment at the end of year among teacher and in centered teacher mean reading attainment.

2.462e-10 + 1.764e-01 + 1.311e+00 = 1.487

2.462e-10/1.487 = 1.6556826e-10

1.764e-01/1.487 = 0.1186

(2.462e-10 + 1.764e-01)/1.487 ≈ 0.1186

The similarity with respect to reading scores at year one of same school and teacher controlling for scores at reception is about 12%.

(0.1370+0.1277 - (2.462e-10 + 1.764e-01))/0.2647 = 0.33

About 33% of variation of scores at year 1 between teacher and school can be attributed to their centered mean reading attainment scores at reception at teacher level.