nlpsem

CRAN GitHub repo R DOI License: GPL >= 3

nlpsem provides tools for fitting linear and nonlinear longitudinal models within the structural equation modeling (SEM) framework. The package is built on top of OpenMx and is designed for settings where the trajectory shape is nonlinear and may be intrinsically nonlinear rather than a simple reparameterization of a linear growth model.

Version 1.0.0

Quadratic, negative exponential and Jenss-Bayley models are fitted to standardized data and converted back exactly: the estimates, standard errors and likelihood are reported in the original units, and getSpecification() records the scaling. options(nlpsem.standardize = FALSE) fits on the raw scale. Other functional forms and mediation models retain raw-scale fitting.

The 1.0.0.9005 update made EXP, Jenss-Bayley and bilinear spline starting values use per-person stats::nls() with the 0.3 curve formulas and default Gauss-Newton algorithm. The shared initializer supplies this method to all model families. Failed NLS fits use recorded heuristic fallbacks; they are not counted as NLS convergence. The final SEM optimizer is unchanged. The matched comparison protocol explicitly uses CSOLNP and identical saved unfitted models on each platform.

Version 1.0.0 fixes mediation wave/covariance starts, one-class mixture post-processing, posterior normalization and class-count validation, multivariate summary columns, parameter names and confidence-interval labels. It adds getDiagnostics() checks for stored covariance admissibility, Hessian and standard error information, and mixture component sizes. New fits warn when these checks find issues; getDiagnostics() supplies the details without refitting or constraining models.

Mediation disturbance covariance starts use aligned structural regression residuals before numerical path damping. This avoids invalid covariance starts when direct and indirect effects oppose each other or observations are missing, while preserving the per-person NLS method and optimizer controls.

LCSM change plots follow the fitted interval recurrence and rebase selected waves with covariance-aware intervals. getSimData() retains generating growth-curve parameters in truth, identifies their parameterization and time origin in truth_info, and supplies first-occasion LCSM targets in truth_lcsm for quadratic and nonparametric models. A time-zero growth-curve intercept is a different target from an LCSM initial level when the first modeled time is nonzero.

print(fit)
coef(fit)
getDiagnostics(fit)
getSpecification(fit)$specification
plot(fit, draw = FALSE)

The V1.0.0 validation record separates completed checks from the limits of numerical qualification. The fitting-layer reference values were regenerated with 1.0.0.9006; each fit is compared with its reference only after it passes the getDiagnostics() checks (see NEWS.md). The saved examples were regenerated with 1.0.0.9006 (inst/extdata/REGENERATED.txt); getDiagnostics() flags four of them, which the guides note. These stored objects retain their original development-version provenance; they are illustrative examples rather than evidence that every model is admissible.

New estimate tables retain full precision. Older serialized tables retain their historical rounding and need recomputation or refitting to recover precision. S4 slots are preserved. Invalid custom names now fail explicitly instead of recycling. Factor scoring supports single RAM/LISREL models with their own raw data; mixture and multiple-group parent objects are rejected with a clear explanation.

Portfolio positioning

nlpsem is a statistical software and measurement-methods asset. It supports nonlinear longitudinal modeling, latent growth and latent change models, mixture modeling, multivariate longitudinal processes, multiple-group comparisons, and psychometric/measurement-science workflows in R.

For AI evaluation roles, the package is relevant because repeated AI behavior across prompts, models, seeds, raters, and deployment conditions can be studied with the same measurement mindset used for longitudinal human-development and latent-process modeling: define the measurement occasions, model systematic variation, quantify reliability, and separate signal from instability.

For hiring reviewers

This repository demonstrates:

The methods implemented in this package are described in:

Liu, J. (2025). Examination of nonlinear longitudinal processes with latent variables, latent processes, latent changes, and latent classes in the structural equation modeling framework: The R package nlpsem. Behavior Research Methods. https://doi.org/10.3758/s13428-025-02596-4

Connection to AI evaluation

The same measurement-science principles used for longitudinal human-development modeling also inform evaluation of AI system behavior over prompts, models, seeds, raters, and deployment conditions. In both settings, the central questions are how behavior changes across repeated conditions, which sources of variation are meaningful, and how much confidence a reviewer should place in an observed pattern.

Main modeling scenarios

The package supports four broad longitudinal modeling settings:

  1. Univariate longitudinal models with growth factors, with or without time-invariant covariates (TICs) and time-varying covariates (TVCs)
  2. Multivariate longitudinal models for assessing correlated or potentially directional development across multiple processes
  3. Multiple-group longitudinal models for comparing manifested groups
  4. Longitudinal mixture models for identifying latent trajectory classes

Core functions

Model-fitting functions

Post-processing functions

Supported functional forms

For latent growth curve models, nlpsem supports:

For latent change score models, nlpsem supports:

Negative exponential, Jenss-Bayley, and bilinear spline models can be fit in their intrinsically nonlinear forms by setting intrinsic = TRUE.

Installation

The published version is available from CRAN:

install.packages("nlpsem")

To install the development source from a local checkout:

# install.packages("remotes")
remotes::install_local(".")

Quick example

library(nlpsem)

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

data("RMS_dat")
RMS_dat0 <- RMS_dat

# Re-baseline the measurement occasions
baseT <- RMS_dat0$T1
for (i in 1:9) {
  RMS_dat0[[paste0("T", i)]] <- RMS_dat0[[paste0("T", i)]] - baseT
}

# Fit a bilinear spline LGCM with a fixed knot
Math_BLS <- getLGCM(
  dat = RMS_dat0,
  t_var = "T",
  y_var = "M",
  curveFun = "BLS",
  intrinsic = FALSE,
  records = 1:9,
  paramOut = TRUE
)

# Inspect estimates
printTable(Math_BLS)

Earlier changes in version 0.4

Version 0.4 keeps the modeling scope of version 0.3 while substantially improving robustness, usability, and documentation.

Highlights include:

See NEWS.md for a more comprehensive summary of changes from version 0.3.

Documentation

The package includes an overview vignette and scenario-specific example vignettes:

License

GPL (>= 3)