name: sem-fits
description: SEM fits in Compose — a fits entry holding one MAT_SEM matrix fits the structural equation model once and binds its parameters by name; ATTR_SEM_SCORE params.fit scores any slot's rows from it, row-local and bit-equal to the inline fit. A save writes the fit to a .pulse-sem.json file that a later request loads with models and scores from bit-equal. The fit request, the response shape, saving and loading, scoring rules, refusals and failures.
kind: design
type: guide
applies_to: compose, predict
covers: [SEM, SEM fit, latent score, factor score, fits, compose, save, models, .pulse-sem.json, MAT_SEM, ATTR_SEM_SCORE]
requires: [MAT_SEM, ATTR_SEM_SCORE, capability:compose_fits]
SEM fits
A SEM fit is a Compose fits entry (compose-fits) whose request holds exactly one MAT_SEM matrix and no regression. It fits the model ONCE, before any slot, and binds its parameters under the entry’s name. Use it when several slots score the same latents — waves, segments, a train / holdout split — or when the fit rows differ from the scored rows.
{
"fits": [{"name": "brand", "request": {
"cohort": {"filename": "survey.pulse"},
"matrices": [{"type": "MAT_SEM", "vector": "ratings",
"params": {"model": "quality =~ q1 + q2 + q3\nvalue =~ v1 + v2 + v3", "group": "wave",
"group_equal": ["loadings", "intercepts"]}}]}}],
"requests": [{"label": "scored", "cohort": {"filename": "survey.pulse"},
"attributes": [{"type": "ATTR_SEM_SCORE", "label": "value_score", "vector": "ratings",
"params": {"fit": "brand", "latent": "value"}}],
"groups": [{"type": "<category grouper>", "field": "wave"}],
"aggregations": [{"type": "<mean>", "field": "value_score"}]}]
}
The fit
- Every
MAT_SEMknob applies (op-mat-sem,sem-modeling): the model,meanstructure,group/group_equal/group_partial, the solver settings. Its own cohort, filters and weight decide the fit rows. - The response’s
fits.<name>is{"sem": {...}}:operator,model, memberlabels/members, the model’sobserved/inner/latentsorders,estimator,conventions, the knobs,basis,n,sum_weights,dof,n_params, the solver’sconverged/status/iterations, andgroups— per level itsn,sum_weightsand the matriceslambda(observed × inner),beta,psi,theta,nu,alpha,sample_meanat full precision. An ordinal fit (estimatordwls/wlsmv) addsordered,categories(each one’s values, ascending) and per groupthresholds; its file issem_format_version2. A fit grouped by a computed field addsgroup_derivedand its declaredgroup_levels(value,label); its file is version 3 (sem-groups). The fit’s own estimates table is not repeated; runMAT_SEMin a slot to read it. - A
savewrites a SEM fit file (fits/brand.pulse-sem.json; atomic, every figure at full precision; another suffix isPULSE_MODEL_SAVE_INVALID, an overwrite warnsPULSE_MODEL_OVERWRITTEN). A later request loads it withmodels: [{"name": "brand", "path": "fits/brand.pulse-sem.json"}]— the suffix picks the kind — and scores from it bit-equal to the in-compose fit, chain stages included. A file whose model does not rebuild its stored orders isPULSE_MODEL_FILE_INVALID.
Scoring from it
ATTR_SEM_SCORE with params.fit takes only latent, method, labels and missing; any model knob or fit_on beside it is refused (fit_and_model, fit_and_fit_on). The slot:
- aligns its members to the fit’s labels BY LABEL (
PULSE_VECTOR_REFERENCE_MISMATCHwhen they differ); - reads each row’s group from the fit’s
groupfield, matched by level LABEL, so a fit taken on one cohort scores any cohort holding the members and the field (a computed group: the scoring request computes it, elsefit_group_field); a level the fit has no parameters for scores null withPULSE_SEM_SCORE_LEVEL_UNSEEN; - scores every row to the bit of the inline fit with the same knobs over the same fit rows;
- is row-local: it streams beside groupers and features, fuses into a crosstab, and merges across shards and chain stages (the inline form is two-pass and buffers there).
The inline fit’s warnings carry over: too few fit rows or negative degrees of freedom null every score; a solver stop short of its tolerance or the nearest positive-definite substitute scores with a warning.
Kinds and failures
- One namespace holds regression, vector and SEM fits. A SEM fit named by a vector consumer (a fitted attribute, a matrix
params.fit) or a regression score, or a vector / regression fit named byATTR_SEM_SCORE, isPULSE_MODEL_KIND_MISMATCH(details.kind,expected); an unbound name isPULSE_MODEL_UNKNOWNlisting the SEM fits. - A
MAT_SEMfailing on its data (a thin or single group, a singular covariance, an undefined input) fails the fit alone: its entry is{"sem": {operator, error}}, composewarningsgainPULSE_SLOT_FAILED, and every score from it is null withPULSE_FIT_UNAVAILABLE. PredictComposelists the fit as{name, cohort, sem: {operator, labels, members}}and judges every reference’s name, kind and labels as the runtime does.
See
compose-fits— thefitsslot, names, failures.sem-comparison— two SEM fits compared (chi-square difference).op-attr-sem-score— the scoring attribute.sem-modeling— conventions, means and multi-group fits.vector-row-scores— the row-local versus two-pass rule.- Scores as fields (wave means, an OLS on the scores):
pulse_examples_search tags=[compose, multivariate, regression].