Bivariate Growth Model - Multilevel & SEM Implementation in R
Nilam Ram, Kevin Grimm, et al.
1 Overview
This tutorial illustrates fitting of multivariate (bivariate) linear growth models in the multilevel and SEM frameworks in R.
Example data and code are drawn from Chapter 8 of Grimm, Ram, and Estabrook (2017). Specifically, using the NLSY-CYA Dataset we examine how individual differences in change in children’s mathematics achievement across grade are related to individual differences in change in children’s hyperactivity (as rated by teachers) across grade. Please see the book chapter for additional interpretations and insights about the analyses.
1.0.1 Preliminaries - Loading libraries used in this script.
1.0.2 Preliminaries - Data Description
For our examples, we use the mathematics achievement scores from the NLSY-CYA Long Data.
Load the repeated measures data (long format)
#set filepath for data file
filepath <- "https://raw.githubusercontent.com/LRI-2/Data/main/GrowthModeling/nlsy_math_hyp_long_R.dat"
#read in the text data file using the url() function
dat <- read.table(file=url(filepath),
na.strings = ".") #indicates the missing data designator
#copy data with new name
nlsy_math_hyp_long <- dat
#Add names the columns of the data set
names(nlsy_math_hyp_long) = c('id', 'female', 'lb_wght', 'anti_k1',
'math', 'comp', 'rec', 'bpi', 'as', 'anx', 'hd',
'hyp', 'dp', 'wd',
'grade', 'occ', 'age', 'men', 'spring', 'anti')
#reducing to variables of interest
nlsy_math_hyp_long <- nlsy_math_hyp_long[ ,c("id","grade","math","hyp")]
#view the first few observations in the data set
head(nlsy_math_hyp_long, 10)
id | grade | math | hyp |
---|---|---|---|
201 | 3 | 38 | 0 |
201 | 5 | 55 | 0 |
303 | 2 | 26 | 1 |
303 | 5 | 33 | 1 |
2702 | 2 | 56 | 2 |
2702 | 4 | 58 | 3 |
2702 | 8 | 80 | 3 |
4303 | 3 | 41 | 1 |
4303 | 4 | 58 | 1 |
5002 | 4 | 46 | 3 |
Our specific interest is intraindividual change in the repeated measures of math
and hyp
across grade
.
As noted in Chapter 2 , it is important to plot the data to obtain a better understanding of the structure and form of the observed phenomenon.
Longitudinal Plot of Math across Grade at Testing
#intraindividual change trajetories
ggplot(data=nlsy_math_hyp_long, #data set
aes(x = grade, y = math, group = id)) + #setting variables
geom_point(size=.5) + #adding points to plot
geom_line() + #adding lines to plot
theme_bw() + #changing style/background
#setting the x-axis with breaks and labels
scale_x_continuous(limits=c(2,8),
breaks = c(2,3,4,5,6,7,8),
name = "Grade at Testing") +
#setting the y-axis with limits breaks and labels
scale_y_continuous(limits=c(10,90),
breaks = c(10,30,50,70,90),
name = "PIAT Mathematics")