name: sem-modeling
description: Structural equation modelling with MAT_SEM — which convention a fit follows (semopy's covariance-only default or lavaan's) and how to read the outputs. The meanstructure param and the ~ 1 syntax for intercepts and latent means. Multi-group fits and the invariance ladder (group_equal, group_partial, c(...) modifiers).
kind: design
type: guide
applies_to: process, compose, predict
covers: [SEM, structural equation model, CFA, mean structure, intercepts, latent means, multi-group, measurement invariance, group_equal, lavaan, semopy, fit indices]
requires: [MAT_SEM]
Structural equation modelling
MAT_SEM fits a lavaan / semopy model to one vector’s members (params: op-mat-sem).
Which convention applies
| The slot sets… | Convention | What follows |
|---|---|---|
| no lavaan-only feature (a covariance-only model) | semopy 2.3.11’s default fit | SLSQP with semopy’s early stop at ftol 1e-6, variances bounded at 0, semopy’s calc_stats (loglik is the minimised discrepancy, GFI = NFI), estimates columns estimate … p_value |
params.meanstructure: true, or any x ~ 1 / f ~ 1 line | lavaan’s ML fit (meanstructure = TRUE, expected information, fixed.x) | Fisher scoring to the optimum (solver defaults to fisher; slsqp stays available), variances unbounded, lavaan’s χ² and fit indices, Wald ci_lower / ci_upper columns |
Under lavaan conventions:
chi2= N ×objective;dofcounts the means (p(p+1)/2 + p moments, less an observed exogenous block’s own moments);- the baseline is the independence model (variances and means free, covariances 0);
rmseadivides by N;cfi,tli,nfiare lavaan’s;gfi/agfiare lavaan’sgfi_lisrel/agfi_lisrel(lavaan’s ownagfi);loglikis the log-likelihood, andaic/bicderive from it.nfiisnullwhendofexceedsdof_baseline(1 when saturated);- a
~~row between two variables hasstd_estimate= their residual correlation (lavaan’sstd.all).
The two paths can report a different chi2 for one covariance model: compare on ONE convention, meanstructure set on every slot.
Modelling means
meanstructure: truefrees every observed intercept and fixes every latent mean to 0. An observed exogenous variable’s mean (a pure predictor) is fixed to its sample mean (lavaan’sfixed.x) and hidden from the table, as its variance is.x ~ 1frees an intercept,x ~ 0*1fixes it,x ~ a*1labels it (equal across everya*1).f ~ 1frees a latent mean.- To identify a free latent mean, fix its marker’s intercept:
f ~ 1plusx1 ~ 0*1. - A
~ 1line switches the mean structure on regardless ofmeanstructure.
Reading the outputs
auxiliary.estimatesgainsx ~1rows: intercepts for observed variables, means for latents.std_estimateis the estimate over the variable’s model-implied SD.auxiliary.implied_means(μ(θ̂)) andobserved_means(listwise sample means) carry ameancolumn per member. Their gap: mean misfit.ci_lower/ci_upper: Wald intervals, 95% by default (estimate ± 1.96 SE; other levels:sem-bootstrap);nullon a fixed row.
Multi-group fits
params.group names a categorical, packed_bool or u4 / u8 field, or a computed value (sem-groups). Its levels are the groups of ONE joint fit (lavaan’s group =):
- Configural (no
group_equal): every parameter is free per group. A labelled parameter (a*x) is one value in every group, as lavaan reads a label. - A group fit always models the means and follows lavaan.
- The levels are the values that hold rows, in dictionary order (else ascending). A null group drops the row. Predict’s
group_levelsbounds them. estimatesrows are[level] lval op rval.vectors.groupandvectors.labelgive each row’s level and model label (recordsrows addgroup,label).primaryis thegroup_referencelevel’s Σ̂ (default: the first level). Per level, the auxiliaries areimplied_covariance.<level>,residual_covariance.<level>,implied_means.<level>andobserved_means.<level>.- The scalars are joint (
chi2sums the groups,rmseacarries lavaan’s √G), pluschi2_group_<level>andn_group_<level>(the group’s size N*). - Refused: request
groups, a standardizing vector, another field type, a one-entry dictionary. - The slot fails alone (
PULSE_MATRIX_INSUFFICIENT_N) on fewer than two levels with rows, on a level with no more rows than observed variables, or on a reference level without rows.
Invariance
group_equalholds lavaangroup.equalclasses equal across groups:loadings,intercepts,means,residuals,residual.covariances,lv.variances,lv.covariances,regressions(thresholds:sem-ordinal). Metric =["loadings"], scalar =["loadings","intercepts"].- Equal intercepts (without
means) free the latent means outside thegroup_referencelevel, which stays at 0. They read in marker units: the non-reference level’s shift on each factor. group_partialfrees rows from their class, spelled as lavaan does:v2~1,f=~x2,x1~~x2. A freed marker loading is free outside the reference.- A marker loading stays 1 in every group. A labelled row keeps its label’s equality, not its class’s.
c(a1,a2)*x/c(0.5,NA)*xset a label or value per level, in level order (categorical orpacked_boolfield only).NA*xfrees a loading (on a first indicator: no marker).- Ladder: one slot per step, or a zip sweep over
group_equal(a comma-separated string,""= configural): axesstep[configural, metric, scalar] andeq["",loadings,loadings,intercepts], label{{step}}. Comparechi2,dof,cfi,rmseastep to step; test the Δχ² withcompare(sem-comparison). - Examples:
pulse_examples_search tags=[matrix, multivariate](one slot per step),tags=[compose, multivariate](the sweep).
Members
- Standardized: vector
standardize: "zscore"(not withgroup). - Derived variable: an attribute / feature label as a member.
See
op-mat-semsem-bootstrap— bootstrap standard errors and percentile intervals.sem-defined-parameters—:=indirect and contribution effects.sem-comparison— a step vs the last (compare).op-attr-sem-score,sem-fits— per-row latent scores (regression / Bartlett; inline, compose or saved fit) for group means and regressions.multivariate-design— which operator answers which question.matrix-results— slot, encodings, refusals.