Linear Growth Model – Multilevel Modeling Implementation in R

1 Overview

This tutorial illustrates fitting of linear growth models in the multilevel framework in R using both the nlme and lme4 packages. Knowing how to fit the models in different packages can be helpful when working with more complex models because each package has both advantages and limitations.

Example data and code are drawn from Chapter 3 of Grimm, Ram, and Estabrook (2017). Specifically, we examine change in children’s mathematics achievement through elementary and middle school 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(ggplot2)  #for plotting
library(nlme) #for mixed effects models
library(lme4) #for mixed effects models

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')

#view the first few observations in the data set 
head(nlsy_math_long, 10)
id female lb_wght anti_k1 math grade occ age men spring anti
201 1 0 0 38 3 2 111 0 1 0
201 1 0 0 55 5 3 135 1 1 0
303 1 0 1 26 2 2 121 0 1 2
303 1 0 1 33 5 3 145 0 1 2
2702 0 0 0 56 2 2 100 NA 1 0
2702 0 0 0 58 4 3 125 NA 1 2
2702 0 0 0 80 8 4 173 NA 1 2
4303 1 0 0 41 3 2 115 0 0 1
4303 1 0 0 58 4 3 135 0 1 2
5002 0 0 4 46 4 2 117 NA 1 4

Our specific interest is in how the repeated measures of math change 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. Here, we want to examine the data to make sure a growth model would be an appropriate analysis for the data (i.e., we need to check that there is in fact growth to model).

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")