Examples of Multivariate Longitudinal Models

The saved examples below were generated with nlpsem 1.0.0.9006; extdata/REGENERATED.txt records the versions and how the fits compare with the previous ones. Rendering this guide does not refit its disabled model-fitting chunks. Refit with the current version for a new analysis, use getDiagnostics() to check admissibility and uncertainty, and compare multiple starts for difficult nonlinear or mixture models. These examples are not evidence of numerical qualification.

Load nlpsem package, dependent packages and set CSOLNP as the optimizer

library(nlpsem)
mxOption(model = NULL, key = "Default optimizer", "CSOLNP", reset = FALSE)

Load pre-computed models

load(system.file("extdata", "getMGM_examples.RData", package = "nlpsem"))

Load example data and preprocess data

# Load ECLS-K (2011) data
data("RMS_dat")
RMS_dat0 <- RMS_dat
# Re-baseline the data so that the estimated initial status is for the
# starting point of the study
baseT <- RMS_dat0$T1
RMS_dat0$T1 <- RMS_dat0$T1 - baseT
RMS_dat0$T2 <- RMS_dat0$T2 - baseT
RMS_dat0$T3 <- RMS_dat0$T3 - baseT
RMS_dat0$T4 <- RMS_dat0$T4 - baseT
RMS_dat0$T5 <- RMS_dat0$T5 - baseT
RMS_dat0$T6 <- RMS_dat0$T6 - baseT
RMS_dat0$T7 <- RMS_dat0$T7 - baseT
RMS_dat0$T8 <- RMS_dat0$T8 - baseT
RMS_dat0$T9 <- RMS_dat0$T9 - baseT
xstarts <- mean(baseT)

Example 1: Fit multivariate bilinear spline LGCMs fixed knots to evaluate the development of reading and mathematics ability from Kindergarten to Grade 5.

RM_PLGCM.r <- getMGM(
  dat = RMS_dat0, t_var = c("T", "T"), y_var = c("R", "M"), curveFun = "BLS",
  intrinsic = FALSE, records = list(1:9, 1:9), y_model = "LGCM",
  tries = 10, paramOut = TRUE
  )
Figure1 <- getFigure(
  model = RM_PLGCM.r@mxOutput, sub_Model = "MGM", y_var = c("R", "M"), curveFun = "BLS", 
  y_model = "LGCM", t_var = c("T", "T"), records = list(1:9, 1:9), xstarts = xstarts, 
  xlab = "Month", outcome = c("Reading", "Mathematics")
)
show(Figure1)
#> figOutput Object
#> --------------------
#> Trajectories: 2 
#> 
#> Trajectory 1 :
#>   Figure 1:
#> `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

Reading mean trajectory over months from a bivariate bilinear spline growth model with fixed knots, comparing the fitted mean and smoothed observed mean with pointwise 95 percent confidence limits.

#> 
#> Trajectory 2 :
#>   Figure 1:
#> `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

Mathematics mean trajectory over months from a bivariate bilinear spline growth model with fixed knots, comparing the fitted mean and smoothed observed mean with pointwise 95 percent confidence limits.

Example 2: Fit multivariate bilinear spline LGCMs with random knots to evaluate the development of reading and mathematics ability from Kindergarten to Grade 5.

RM_PLGCM.f <- getMGM(
  dat = RMS_dat0, t_var = c("T", "T"), y_var = c("R", "M"), curveFun = "BLS",
  intrinsic = TRUE, records = list(1:9, 1:9), y_model = "LGCM",
  tries = 10, paramOut = TRUE
  )
Figure2 <- getFigure(
  model = RM_PLGCM.f@mxOutput, sub_Model = "MGM", y_var = c("R", "M"), curveFun = "BLS", 
  y_model = "LGCM", t_var = c("T", "T"), records = list(1:9, 1:9), xstarts = xstarts, 
  xlab = "Month", outcome = c("Reading", "Mathematics")
)
show(Figure2)
#> figOutput Object
#> --------------------
#> Trajectories: 2 
#> 
#> Trajectory 1 :
#>   Figure 1:
#> `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

Reading mean trajectory over months from a bivariate bilinear spline growth model with random knots, comparing the fitted mean and smoothed observed mean with pointwise 95 percent confidence limits.

#> 
#> Trajectory 2 :
#>   Figure 1:
#> `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

Mathematics mean trajectory over months from a bivariate bilinear spline growth model with random knots, comparing the fitted mean and smoothed observed mean with pointwise 95 percent confidence limits.