Multiple-group 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", "getMGroup_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
# Standardize time-invariant covariates (TICs)
## ex1 and ex2 are standardized growth TICs in models
RMS_dat0$ex1 <- scale(RMS_dat0$Approach_to_Learning)
RMS_dat0$ex2 <- scale(RMS_dat0$Attention_focus)
xstarts <- mean(baseT)

Example 1: Fit multiple group bilinear spline LGCM to evaluate the difference in the development of mathematics ability

set.seed(20191029)
MGroup_Math_BLS_LGCM_f <-  getMGroup(
  dat = RMS_dat0, grp_var = "SEX", sub_Model = "LGCM", y_var = "M", t_var = "T",
  records = 1:9, curveFun = "BLS", intrinsic = TRUE, tries = 20
)
Figure1 <- getFigure(
  model = MGroup_Math_BLS_LGCM_f@mxOutput, nClass = 2, cluster_TIC = NULL, grp_var = "SEX",
  sub_Model = "LGCM", y_var = "M", curveFun = "BLS", y_model = "LGCM", t_var = "T",
  records = 1:9, m_var = NULL, x_var = NULL, x_type = NULL, xstarts = xstarts,
  xlab = "Month", outcome = "Mathematics"
)
show(Figure1)
#> figOutput Object
#> --------------------
#> Trajectories: 1 
#> Figure 1:
#> `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

Mathematics mean trajectory over months from a bilinear spline growth model, with separate curves for the two SEX groups, comparing the fitted mean and smoothed observed mean with pointwise 95 percent confidence limits.

The saved solution of this model reaches optimizer status 0, but getDiagnostics() reports a slightly indefinite covariance matrix of the growth factors in the first group (smallest eigenvalue about -0.003), so refitting the call above returns it with a warning. An earlier fit of the same call (nlpsem 1.0.0.9000) reached an admissible solution with a lower likelihood (-2LL 31245.64 against 31204.94). Compare the solutions from several starts, or consider a fixed knot, before interpreting the group-specific variances.

Example 2: Fit multiple group negative exponential LGCM with time-invariant covariates (TICs) to evaluate the difference in the development of reading ability. This model includes two growth TICs, baseline values of teacher-reported approach to learning and attentional focus. Point estimates and corresponding standard errors (SEs) of all parameters are presented within the original parameter space.

set.seed(20191029)
MGroup_Read_EXP_LGCM_TIC_r <- getMGroup(
  dat = RMS_dat0, grp_var = "SEX", sub_Model = "LGCM", y_var = "R", t_var = "T",
  records = 1:9, curveFun = "EXP", intrinsic = FALSE,
  growth_TIC = c("ex1", "ex2"), paramOut = TRUE
)
MGroup_Read_EXP_LGCM_TIC_r@Estimates
Figure2 <- getFigure(
  model = MGroup_Read_EXP_LGCM_TIC_r@mxOutput, nClass = 2, cluster_TIC = NULL, grp_var = "SEX",
  sub_Model = "LGCM", y_var = "R", curveFun = "EXP", y_model = "LGCM", t_var = "T",
  records = 1:9, m_var = NULL, x_var = NULL, x_type = NULL, xstarts = xstarts,
  xlab = "Month", outcome = "Reading"
)
show(Figure2)