Skip to contents

The primary high-level function for users who work with umxRAM() models. It:

  1. Translates the model to lavaan syntax via umx_to_lavaan().

  2. Extracts raw data from model@data@observed.

  3. Fits the model with fastsem_fit().

  4. Writes estimates back into the model matrices and populates model@output so that summary(), omxGetParameters(), and umxCompare() work as if mxRun() had been called.

Usage

run_fastsem(model, control = list(), engine = c("auto", "ram", "lavaan"))

Arguments

model

An MxModel as returned by umxRAM() (or a bare mxModel container holding submodels for multi-group use). The model must have raw (row-level) data in model@data@observed.

control

Optional named list passed to the optimizer. Recognized fields: maxIter (int), tol (gradient-norm tolerance), ftol (objective-change tolerance), tryHard (extra retry rounds on non-convergence; each round multiplies maxIter by 3 and divides tol by 10). Any field absent or 0/0.0 uses the core default.

engine

One of "auto", "ram", "lavaan". For multi-group models, "auto" selects the RAM engine. For single-group models, the lavaan engine is always used (RAM single-group is not yet wired in the R wrapper).

Value

The same MxModel object with:

Matrix values updated

A, S, and M matrices hold the fastsem point estimates.

@output populated

$estimate, $standardErrors, $fit (-2lnL), $Chi, $ChiDoF, plus $.fastsem_* slots for the raw fastsem result list.

@.wasRun set to TRUE

Makes summary() and umxCompare() work.

Multi-group models

When model@submodels is non-empty, run_fastsem() fits the joint multi-group model and injects per-group estimates back into each submodel. Two engines are available (selected via engine):

  • "ram" (default for multi-group) sends the OpenMx RAM matrices (A, S, optionally M) directly to fastsem's Nim core via fitSemFromMatricesMultigroupR. This bypasses the lavaan-syntax round-trip and honors cross-group fixed covariances exactly (e.g. cross-twin A=1.0 in MZ vs 0.5 in DZ).

  • "lavaan" stacks data with a fastsem_grp indicator, builds a combined lavaan syntax with c() per-group annotations, and fits via fastsem_fit(). Use this when the RAM engine errors on a model that uses features it does not yet support (definition variables, ordinal thresholds, configural cross-group different-label free parameters). Parameters that carry the same OpenMx label in all submodels are equated; others are group-specific.

See also

umx_to_lavaan() for syntax inspection; umx_to_fastsem() for the raw result list without inject-back; fastsem_fit() for fitting from raw lavaan syntax.

Examples

if (FALSE) { # \dontrun{
library(umx)

# ── CFA ──────────────────────────────────────────────────────────────────
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
)
m_fit <- run_fastsem(m)
summary(m_fit)
omxGetParameters(m_fit)

# ── Multi-group CFA ───────────────────────────────────────────────────────
data(HolzingerSwineford1939, package = "lavaan")
hs <- HolzingerSwineford1939

mg_p <- umxRAM("mg_p",
  umxPath(from = "g", to = c("x1","x2","x3")),
  umxPath(v1m0 = "g"), umxPath(var = c("x1","x2","x3")),
  umxPath(means = c("x1","x2","x3")),
  data = hs[hs$school == "Pasteur", c("x1","x2","x3")]
)
mg_gw <- umxRAM("mg_gw",
  umxPath(from = "g", to = c("x1","x2","x3")),
  umxPath(v1m0 = "g"), umxPath(var = c("x1","x2","x3")),
  umxPath(means = c("x1","x2","x3")),
  data = hs[hs$school == "Grant-White", c("x1","x2","x3")]
)
r <- run_fastsem(mxModel("HS_mg", mg_p, mg_gw))
omxGetParameters(r@submodels$mg_p)
} # }