# load package
pacman::p_load(mlmRev, tidyverse, lme4, nlme)
# input data
dta <- read.table("iq_language.txt", header = T)
#
head(dta)
## School Pupil IQ Language Group_size IQ_c School_mean Group_mean
## 1 1 17001 15.0 46 29 3.1659379 -1.51406 5.9
## 2 1 17002 14.5 45 29 2.6659379 -1.51406 5.9
## 3 1 17003 9.5 33 29 -2.3340621 -1.51406 5.9
## 4 1 17004 11.0 46 29 -0.8340621 -1.51406 5.9
## 5 1 17005 8.0 20 29 -3.8340621 -1.51406 5.9
## 6 1 17006 9.5 30 29 -2.3340621 -1.51406 5.9
## SES_c
## 1 -4.811981
## 2 -17.811981
## 3 -12.811981
## 4 -4.811981
## 5 -17.811981
## 6 -17.811981
summary(m0 <- lmer(Language ~ (1|School), data = dta))
## Linear mixed model fit by REML ['lmerMod']
## Formula: Language ~ (1 | School)
## Data: dta
##
## REML criterion at convergence: 16253.1
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.11618 -0.65703 0.07597 0.74128 2.50639
##
## Random effects:
## Groups Name Variance Std.Dev.
## School (Intercept) 19.63 4.431
## Residual 64.56 8.035
## Number of obs: 2287, groups: School, 131
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 40.3624 0.4282 94.26
The estimated overall language score is 40.36.
The estimated between school variance in language score is 19.63.
The variation between student within the same school is estimated to be 64.56.
The between school variance is about 19.63 / (19.63 + 64.56) = 0.2331631 (23%)of the total variance. This is the intraclass correlation.
summary(m1 <- lmer(Language ~ IQ_c + (1|School), data = dta))
## Linear mixed model fit by REML ['lmerMod']
## Formula: Language ~ IQ_c + (1 | School)
## Data: dta
##
## REML criterion at convergence: 15255.8
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -4.0939 -0.6375 0.0579 0.7061 3.1448
##
## Random effects:
## Groups Name Variance Std.Dev.
## School (Intercept) 9.602 3.099
## Residual 42.245 6.500
## Number of obs: 2287, groups: School, 131
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 40.60823 0.30819 131.8
## IQ_c 2.48759 0.07008 35.5
##
## Correlation of Fixed Effects:
## (Intr)
## IQ_c 0.018
After adjusting for the IQ score, the between school variance is about 9.602/(9.602 + 42.245) = 0.1851988
After adjusting for the IQ score, the estimated overall language score is 40.6
sjPlot::tab_model(m0, m1, show.p=FALSE, show.r2=FALSE, show.obs=FALSE, show.ngroups=FALSE, show.se=TRUE, show.ci=FALSE)
Language | Language | |||
---|---|---|---|---|
Predictors | Estimates | std. Error | Estimates | std. Error |
(Intercept) | 40.36 | 0.43 | 40.61 | 0.31 |
IQ_c | 2.49 | 0.07 | ||
Random Effects | ||||
σ2 | 64.56 | 42.24 | ||
τ00 | 19.63 School | 9.60 School | ||
ICC | 0.23 | 0.19 |
About 51% (19.63-9.6/19.63) of variation in language scores between schools can be attributed to differences in preschool scores between schools.