build_syntax
Generates Mplus input syntax for common model types (CFA, EFA, SEM, mediation, growth, mixture, invariance, two-level), returning editable text for review before running it in Mplus.
Instructions
Write Mplus input syntax for a standard model family (cfa, efa, path, sem, mediation, growth, lpa, lca, invariance, twolevel, custom). Returns the syntax as text - it does not run it. Read it, adjust it, then pass it to run_syntax. Anything the template does not cover goes in model_extra, analysis_extra or model_constraint.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| x | No | Mediation: the predictor. | |
| y | No | Mediation: the outcome. | |
| plot | No | PLOT type, e.g. 'PLOT3'. | |
| save | No | What to save, e.g. 'FSCORES' or 'CPROBABILITIES'. | |
| names | Yes | Every column in file order, e.g. 'id y1-y6 x1 x2'. | |
| title | No | Title line for the output. | |
| output | No | OUTPUT options. Default depends on the model type. | |
| starts | No | Mixture random starts, e.g. '500 100'. | |
| weight | No | Sampling weight variable. | |
| within | No | Two-level: %WITHIN% lines. | |
| between | No | Two-level: %BETWEEN% lines. | |
| classes | No | Number of latent classes for lpa/lca. | |
| cluster | No | Cluster variable for TWOLEVEL or COMPLEX. | |
| factors | No | Factors for cfa/sem/invariance, e.g. {'F1': ['y1', 'y2', 'y3']}. | |
| missing | No | MISSING specification, e.g. 'ALL (-999)'. | ALL (-999) |
| grouping | No | Grouping spec, e.g. 'sex (1 = male 2 = female)'. | |
| auxiliary | No | AUXILIARY spec, e.g. '(R3STEP) x1 x2'. | |
| bootstrap | No | Bootstrap draws; adds CINTERVAL (BOOTSTRAP). | |
| data_file | Yes | Data file name as Mplus will see it, e.g. 'scale.dat'. | |
| efa_range | No | EFA factor range, e.g. [1, 4]. | |
| estimator | No | ML, MLR, WLSMV, BAYES ... | |
| mediators | No | Mediation: one or more mediators. | |
| quadratic | No | Growth: add a quadratic slope factor. | |
| covariates | No | Mediation: controls for m and y. | |
| idvariable | No | ID variable, carried into SAVEDATA. | |
| indicators | No | Growth: repeated measures in time order. Mixture: class indicators. | |
| model_type | Yes | cfa, efa, path, sem, mediation, growth, lpa, lca, invariance, twolevel or custom. | |
| processors | No | PROCESSORS for parallel estimation. | |
| timescores | No | Growth: time scores, one per indicator. Default 0,1,2 ... | |
| categorical | No | Ordered categorical outcomes, e.g. 'u1-u6'. | |
| covariances | No | WITH statements, e.g. ['y1 WITH y2;']. | |
| model_lines | No | Extra MODEL lines, verbatim. | |
| regressions | No | MODEL lines such as ['y ON x1 x2;', 'f1 ON x1;']. | |
| usevariables | No | Variables the model uses. Default: all of NAMES. | |
| savedata_file | No | SAVEDATA file name. | |
| analysis_extra | No | Extra ANALYSIS lines, e.g. ['TYPE = COMPLEX;']. | |
| class_specific | No | Mixture: lines for class blocks, e.g. ['%c#1%', '[y1*2];']. | |
| free_variances | No | Mixture: free indicator variances across classes. | |
| model_constraint | No | MODEL CONSTRAINT lines, verbatim. | |
| growth_regressions | No | Growth: e.g. ['i s ON x;']. |