Eighty-nine children’s scores on the reading subtest of the Peabody Individual Achievement Test (PIAT) were recorded. Each child was 6 years old in 1986, the first year** of data collection. | Column 1: Child ID
| Column 2: Wave (1 = 1986, 2 = 1988, 3 = 1990)
| Column 3: Child’s expected age on each measurement occasion
| Column 4: Age in years
| Column 5: Child’s PIAT score
# Loading package
pacman::p_load(tidyverse, afex, segmented, foreign, haven, lme4, lmerTest, ggplot2, Rmisc, car)
# data input
dta2 <- read.table("C:/Users/HANK/Desktop/HOMEWORK/reading_piat.txt", header = T)
head(dta2)
## ID Wave Age_G Age PIAT
## 1 1 1 6.5 6.0000 18
## 2 1 2 8.5 8.3333 35
## 3 1 3 10.5 10.3333 59
## 4 2 1 6.5 6.0000 18
## 5 2 2 8.5 8.5000 25
## 6 2 3 10.5 10.5833 28
str(dta2)
## 'data.frame': 267 obs. of 5 variables:
## $ ID : int 1 1 1 2 2 2 3 3 3 4 ...
## $ Wave : int 1 2 3 1 2 3 1 2 3 1 ...
## $ Age_G: num 6.5 8.5 10.5 6.5 8.5 10.5 6.5 8.5 10.5 6.5 ...
## $ Age : num 6 8.33 10.33 6 8.5 ...
## $ PIAT : int 18 35 59 18 25 28 18 23 32 18 ...
dta2 <- dta2 %>%
mutate(Age_c = Age - 6.5)
ggplot(dta2, aes(Age, PIAT, group = ID, color = Wave))+
geom_point(size = rel(1))+
geom_line() +
labs(x = "Age (year)", y = "Score") +
theme(legend.position = c(.9, .2))
Model:
Scoreij = b0i + b1i × (ageij - 6.5) + εij,
b0i = β0i + U0i, b1i = β1i + U1i, i = 1, 2, …, 89; j = 1, 2, 3,
where εij follows a standard normal distribution with mean zero and SD sigma and (U0i, U1i) is a bivariate normal distribution with a zero mean vector with an unknown covariance matrix.
summary(m1 <- lmer(PIAT ~ Age_c + (Age_c | ID), data = dta2))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: PIAT ~ Age_c + (Age_c | ID)
## Data: dta2
##
## REML criterion at convergence: 1804.1
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.0042 -0.4893 -0.1383 0.4067 3.6892
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## ID (Intercept) 5.507 2.347
## Age_c 3.377 1.838 0.53
## Residual 27.400 5.235
## Number of obs: 267, groups: ID, 89
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 21.0621 0.5630 75.7425 37.41 <2e-16 ***
## Age_c 4.5399 0.2622 87.7555 17.32 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Age_c -0.288