Skip to contents

Inspects the RAM matrices (A, S, M) of an MxModel and generates the extended lavaan syntax string that fastsem_fit() expects. This is called internally by run_fastsem() but is also useful for inspection or for further hand-editing before fitting.

Usage

umx_to_lavaan(model, include_map = FALSE)

Arguments

model

An MxModel as returned by umxRAM() or mxModel().

include_map

Logical (default FALSE). When TRUE returns a list with two elements:

syntax

The lavaan syntax string.

param_map

Named character vector mapping fastsem structural names (e.g. "f->y1") to OpenMx free-parameter labels (e.g. "g_to_y1"). Used by run_fastsem() for inject-back.

Value

Character string (default) or named list when include_map = TRUE.

Translations performed

A matrix (directional)

Latent → manifest paths become factor =~ indicator lines. Latent → latent become ~ regression lines. Manifest → manifest become ~ regression lines. A label starting with "data." is treated as a definition variable and emitted as data.colname * indicator.

S matrix (symmetric)

Free diagonal entries → var ~~ var (with start() or label if set). Fixed non-zero diagonal entries → var ~~ value*var. Free off-diagonal → a ~~ b covariance.

M matrix (means)

Free entries → var ~ 1 (with start() if the starting value is non-zero). Fixed non-zero entries → var ~ value*1.

Bounds

S@lbound / S@ubound / A@lbound / A@uboundlabel > lo / label < hi lines. Variance lower bounds of 0 are suppressed because fastsem's log-variance parameterisation already prevents negative variances.

Equality constraints

Labels appearing on more than one free parameter are emitted as label*var, which fastsem treats as an equality constraint.

See also

run_fastsem() to fit and inject back in one step.

Examples

if (FALSE) { # \dontrun{
library(umx)
df <- as.data.frame(scale(iris[, c(1, 3, 4)]))
names(df) <- c("sl", "pl", "pw")

m <- umxRAM("CFA",
  umxPath(from = "g", to = c("sl", "pl", "pw")),
  umxPath(v1m0 = "g"),
  umxPath(var  = c("sl", "pl", "pw")),
  data = df, autoRun = FALSE
)

# Inspect the generated syntax
cat(umx_to_lavaan(m))

# Include the parameter map for custom inject-back
out <- umx_to_lavaan(m, include_map = TRUE)
str(out$param_map)
} # }