Multiple Group Growth Model – Multilevel & SEM Implementation in R

1 Overview

This tutorial illustrates fitting of multiple group linear growth models in the multilevel and SEM frameworks in R.

Example data and code are drawn from Chapter 6 of Grimm, Ram, and Estabrook (2017). Specifically, using the NLSY-CYA Dataset we examine how change in children’s mathematics achievement across grade differs across groups defined by low (< 5.5 lbs) and normal birth weight. Please see the book chapter for additional interpretations and insights about the analyses.

1.0.1 Preliminaries - Loading libraries used in this script.

library(psych)  #for basic functions
library(plyr)   #for data management
library(ggplot2)  #for plotting
library(nlme) #for mixed effects models
library(lme4) #for mixed effects models
library(lavaan) #for SEM 
library(semPlot) #for making SEM diagrams

1.0.2 Preliminaries - Data Preparation and Description

For our examples, we use the mathematics achievement scores from the NLSY-CYA Long Data.

Load the repeated measures data

#set filepath for data file
filepath <- "https://raw.githubusercontent.com/LRI-2/Data/main/GrowthModeling/nlsy_math_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_long <- dat  

#Add names the columns of the data set
names(nlsy_math_long) = c('id'     , 'female', 'lb_wght', 
                          'anti_k1', 'math'  , 'grade'  ,
                          'occ'    , 'age'   , 'men'    ,
                          'spring' , 'anti')

#reducing to variables of interest 
nlsy_math_long <- nlsy_math_long[ ,c("id","grade","math","lb_wght")]

#adding another dummy code variable for normal birth weight that coded the opposite of the low brithweight variable. 
nlsy_math_long$nb_wght <- 1 - nlsy_math_long$lb_wght

#view the first few observations in the data set 
head(nlsy_math_long, 10)
id grade math lb_wght nb_wght
201 3 38 0 1
201 5 55 0 1
303 2 26 0 1
303 5 33 0 1
2702 2 56 0 1
2702 4 58 0 1
2702 8 80 0 1
4303 3 41 0 1
4303 4 58 0 1
5002 4 46 0 1

Our specific interest is intraindividual change in the repeated measures of math change across grade, and how those those trajectories differ across lb_wght and nb_wght groups.

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. Here, we want to examine the data to see how the repeated measures of math are structured with respect to grade, and how that differs across groups.

Longitudinal Plot of Math across Grade at Testing

#intraindividual change trajetories
ggplot(data=nlsy_math_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") +
  facet_wrap(~lb_wght)