generate_mplus_syntax: Generate Mplus Syntax for ESEM with Target Rotation

View source: R/mplus_syntax.R

generate_mplus_syntaxR Documentation

Generate Mplus Syntax for ESEM with Target Rotation

Description

Generates a complete Mplus .inp file for ESEM with target rotation, using the correct Mplus syntax: separate BY statements per factor, each with its own (*1) label. Primary items always appear first, followed by cross-loading items targeted to zero.

Usage

generate_mplus_syntax(
  factors,
  cfa_factors = NULL,
  regressions = NULL,
  covariances = NULL,
  data_file = "mydata.dat",
  missing_code = 999,
  estimator = if (ordered) "WLSMV" else "MLR",
  output_path = NULL,
  ordered = FALSE
)

Arguments

factors

Named list mapping factor names to their primary indicator names. Example: list(EX = c("y1","y2"), MD = c("y3","y4")).

cfa_factors

Optional named list of additional CFA factors.

regressions

Optional character vector of regression statements.

covariances

Optional character vector of covariance statements.

data_file

Character. Name of the data file. Default "mydata.dat".

missing_code

Missing value code. Default 999. Use "." for files written by MplusAutomation::prepareMplusData(), which writes MISSING = .;.

estimator

Character. Default "WLSMV" when ordered = TRUE, otherwise "MLR".

output_path

Character. Full path to write the .inp file. Returns syntax string invisibly if NULL.

ordered

Logical. TRUE declares the factor indicators CATEGORICAL and uses the theta parameterization, as esem_ordered does. Default FALSE.

Details

Correct output format:

EX BY
  batEX1 batEX2 ... batEX8       <- primary items first
  batMD1~0 ... batCI5~0 (*1);    <- cross-loadings after

MD BY
  batMD1 batMD2 ... batMD5       <- primary items first
  batEX1~0 ... batCI5~0 (*1);    <- cross-loadings after

Value

The Mplus syntax as a character string (invisibly). Writes file if output_path is supplied.

Examples

# Pure syntax generation: builds a Mplus .inp string, no Mplus install needed.
syntax <- generate_mplus_syntax(
  factors = list(
    Visual  = c("x1", "x2", "x3"),
    Textual = c("x4", "x5", "x6"),
    Speed   = c("x7", "x8", "x9")
  ),
  output_path = file.path(tempdir(), "esem_model.inp")
)
cat(syntax)


bifactory documentation built on Oct. 28, 2026, 1:06 a.m.