Growth Model with Continuous Time Variable – Multilevel & SEM Implementation in R

1 Overview

This tutorial illustrates fitting of linear growth models with a continuous time variable in the multilevel and SEM frameworks in R.

Example data and code are drawn from Chapter 4 of Grimm, Ram, and Estabrook (2017). Specifically, we examine change in children’s mathematics achievement across age using the NLSY-CYA Dataset. We fit both No Growth and Linear Growth moodels. 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')

#subset to the variables of interest
nlsy_math_long <- nlsy_math_long[ ,c("id", "math", "grade", "age")]
#view the first few observations in the data set 
head(nlsy_math_long, 10)
id math grade age
201 38 3 111
201 55 5 135
303 26 2 121
303 33 5 145
2702 56 2 100
2702 58 4 125
2702 80 8 173
4303 41 3 115
4303 58 4 135
5002 46 4 117

Our specific interest is in how the repeated measures of math change across age. Note that age is measured in months.

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 age.

Longitudinal Plot of Math across Grade at Testing

#intraindividual change trajetories
ggplot(data=nlsy_math_long,                    #data set
       aes(x = age, 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 = "Age 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")