!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!! MPLUS SYNTAX LINES CANNOT EXCEED 90 CHARACTERS;
!!!!! VARIABLE NAMES AND PARAMETER LABELS CANNOT EXCEED 8 CHARACTERS EACH;
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
TITLE: Example Mplus Model
DATA:
FILE = "C:/[insert_filepath]/filename.dat";
VARIABLE:
NAMES = ID age x1 x2 x3 x4 x5 x6 y1 y2;
MISSING = .;
USEVARIABLES = ID age x1 x2 x3 x4 x5 x6 y1 y2;
ANALYSIS:
TYPE = COMPLEX;
ESTIMATOR = MLR;
MODEL:
! Factor loadings
latent1 BY x1* x2 x3;
latent2 BY x4* x5 x6;
! Covariances between latent factors
latent1 WITH latent2
! Regression paths
y1 ON latent1 + latent2
y2 ON latent1 + latent 2
! Standardize latent factors: fix means to zero
[latent1@0];
[latent2@0];
! Standardize latent factors: fix variances to one
latent1@1;
latent2@1;
OUTPUT:
STDYX;
TECH1;
TECH4;
SAMPSTAT;
MODINDICES (3);
CINTERVAL;
RESIDUAL;
SAVEDATA:
FILE = "C:/[insert_filepath]/filename.dat";
SAVE = FSCORES;
4 Model Title
TITLE: INSERT TITLE HERE
5 Read Data
DATA:
FILE = "C:/[insert_filepath]/filename.dat";
6 Variables
6.1 Specify
Variables
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
CLUSTER = ID;
6.2 Categorical
Variables
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
CATEGORICAL = x1 x2;
6.3 Count Variables
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
COUNT = x1 x2;
6.4 Cluster Variable
There are multiple ways of accounting for nested data in structural equation modeling. One way to account for
nested data is to use multilevel structural equation modeling. Another
approach is to use a cluster variable to generate cluster-robust
standard errors of parameters. To use a cluster variable, specify
CLUSTER under the VARIABLE section, and
specify TYPE = COMPLEX under the ANALYSIS
section:
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
CLUSTER = ID;
ANALYSIS:
TYPE = COMPLEX;
6.5 Individually Varying
Times of Observation
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
TSCORES = age;
6.6 Auxiliary
Variables
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID x1 x2 y1;
AUXILIARY = age;
6.7 Sampling Weight
Variable
VARIABLE:
NAMES = ID wt age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
WEIGHT = wt;
6.8 Multilevel
Variables
Between- and within-cluster variables:
VARIABLE:
NAMES = ID wt age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
WITHIN = x1;
BETWEEN = x2;
7 Analysis
7.1 Analysis Types
TYPE = COMPLEX
TYPE = TWOLEVEL
TYPE = EFA
7.2 Model Estimators
ANALYSIS:
ESTIMATOR = MLR;
MLR: for likert/continuous data
WLSMV: for ordinal/categorical data
BAYES
7.3 Bootstrap Draws
BOOTSTRAP = 2000; ! insert number of bootstrap draws
7.4 Starts
STARTS = 20; ! insert number of initial stage starts and number of final stage optimizations
7.5 Low Covariance
Coverage
To estimate a model with low covariance coverage, lower the
COVERAGE value under the ANALYSIS section:
Other settings you can specify under the “ANALYSIS” section
include:
ANALYSIS:
ESTIMATOR = BAYES;
BCONVERGENCE = .05; ! value of the Gelman-Rubin convergence criterion; ! default is .05; van de Schoot et al. (2014) recommend .01
BITERATIONS = a (b); ! a = maximum, b = minumum number of iterations for each MCMC chain
CHAINS = 4; ! number of chains
PROCESSORS = 4; ! number of computer processors to use
BSEED = 52242; ! set seed for replicability
STVALUES = ml; ! set starting values based on ML estimation
You can specify model priors under the “MODEL PRIORS” section.
Other settings you can specify under the “OUTPUT” section
include:
OUTPUT:
STAND; ! standardized estimates
TECH1; ! model priors
TECH8; ! potential scale reduction (PSR); to evaluate convergence (should be near one)
CINTERVAL; ! posterior predictive intervals (credible intervals)
Other settings you can specify under the “PLOT” section include:
PLOT:
TYPE = PLOT3; ! trace plots, histogram, and kernel density
10 Model
10.1 Define Latent
Variables
MODEL:
latent1 BY x1 x2 x3;
10.2 Regression
Paths
Regress outcome variable on predictor variable(s):
MODEL:
y1 ON x1 x2;
10.3 Covariance
Paths
MODEL:
x1 WITH x2;
10.4 Indirect
Effects
ANALYSIS:
TYPE = GENERAL;
ESTIMATOR = ML;
BOOTSTRAP = 1000;
MODEL:
MODEL INDIRECT:
y IND x;
OUTPUT:
STAND;
CINTERVAL (BOOTSTRAP); !percentile boostrap CI
CINTERVAL (BCBOOTSTRAP); !bias-corrected boostrap CI
10.5
Means/Intercepts
Freely estimate:
MODEL:
[x1];
Fix to zero:
MODEL:
[x1@0];
10.6 Variances
Freely estimate:
MODEL:
x1;
Fix to one:
MODEL:
x1@1;
10.7 Parameter Label
To specify a parameter label, provide the label in parentheses after
the parameter:
MODEL:
latent1 BY x1* x2 x3 (load1-3);
latent2 BY x4* x5 (load5) x6;
10.8 Multigroup
Model
VARIABLE:
NAMES = group x1 x2 x3 y1;
GROUPING = group (0=boys, 1=girls);
MISSING = .;
USEVARIABLES = group x1 x2 x3 y1;
MODEL:
Model boys:
latent BY x1* x2 x3;
[latent@0];
latent@1;
y ~ latent;
Model girls:
latent BY x1* x2 x3;
[latent@0];
latent@1;
y ~ latent;
10.9 Multigroup
Measurement Invariance
10.9.1 Configural
Invariance
VARIABLE:
NAMES = group x1 x2 x3 y1;
GROUPING = group (0=boys, 1=girls);
MISSING = .;
USEVARIABLES = group x1 x2 x3;
MODEL:
Model boys:
latent BY x1* x2 x3;
[latent@0];
latent@1;
Model girls:
latent BY x1* x2 x3;
[latent@0];
latent@1;
10.9.2 Metric (Weak
Factorial) Invariance
VARIABLE:
NAMES = group x1 x2 x3 y1;
GROUPING = group (0=boys, 1=girls);
MISSING = .;
USEVARIABLES = group x1 x2 x3;
MODEL:
Model boys:
latent BY x1* (load1); ! constrain factor loading across groups (same parameter label)
latent BY x2* (load2); ! constrain factor loading across groups (same parameter label)
latent BY x3* (load3); ! constrain factor loading across groups (same parameter label)
[latent@0];
latent@1;
Model girls:
latent BY x1* (load1); ! constrain factor loading across groups (same parameter label)
latent BY x2* (load2); ! constrain factor loading across groups (same parameter label)
latent BY x3* (load3); ! constrain factor loading across groups (same parameter label)
[latent@0];
latent@1;
10.9.3 Scalar (Strong
Factorial) Invariance
VARIABLE:
NAMES = group x1 x2 x3 y1;
GROUPING = group (0=boys, 1=girls);
MISSING = .;
USEVARIABLES = group x1 x2 x3;
MODEL:
Model boys:
latent BY x1* (load1); ! constrain factor loading across groups (same parameter label)
latent BY x2* (load2); ! constrain factor loading across groups (same parameter label)
latent BY x3* (load3); ! constrain factor loading across groups (same parameter label)
[x1] (int1); ! constrain intercept across groups (same parameter label)
[x2] (int2); ! constrain intercept across groups (same parameter label)
[x3] (int3); ! constrain intercept across groups (same parameter label)
[latent@0];
latent@1;
Model girls:
latent BY x1* (load1); ! constrain factor loading across groups (same parameter label)
latent BY x2* (load2); ! constrain factor loading across groups (same parameter label)
latent BY x3* (load3); ! constrain factor loading across groups (same parameter label)
[x1] (int1); ! constrain intercept across groups (same parameter label)
[x2] (int2); ! constrain intercept across groups (same parameter label)
[x3] (int3); ! constrain intercept across groups (same parameter label)
[latent@0];
latent@1;
11 Comments
!This is a comment in Mplus
12 Setting Parameter
Constraints
12.1 Freeing a
Parameter
By default, the first loading on a factor is fixed to zero. You can
freely estimate the parameter by adding an asterisk:
MODEL:
latent1 BY x1* x2 x3;
12.2 Constraing a
Parameter
MODEL:
latent1 BY x1@1 x2 x3;
[latent1@0];
latent1@1;
12.3 Setting Two
Parameters to be Equal
To set two parameters to be equal, provide the same parameter label for each parameter.
12.4 Setting Lower and
Upper Bounds on a Parameter
To set lower and upper bounds on a parameter, you can assign the
parameter a parameter label. Then, you can
assign the constraint to the parameter (via the label) under the
MODEL CONSTRAINT section. For example, to constrain a
parameter between 0–1,
MODEL:
latent1 BY x1* x2 x3 (load3);
MODEL CONSTRAINT:
load3 > 0; load3 < 1;
13 Output
OUTPUT:
STDYX;
TECH1;
TECH4;
SAMPSTAT;
MODINDICES (ALL); ! specify number in parentheses to print only those mod indices that are above a particular chi-square value
CINTERVAL;
RESIDUAL;
14 Save Factor
Scores
SAVEDATA:
FILE = "C:/[insert_filepath]/filename.dat";
SAVE = FSCORES;
15 Multiple
Imputation
For examples of how to conduct multiple imputation in Mplus, see here. To run a model on
multiply imputed data, use the following:
DATA: FILE = "implist.dat"; ! where implist.dat is the name of the *list.dat file saved from the imputation step
TYPE = IMPUTATION;
TITLE: Single-Group Monte Carlo Simulation with Ordinal Items and Common Factor;
MONTECARLO:
NAMES = v1-v5; ! variable names
NOBSERVATIONS = 500; ! number of participants in each sample
NREPS = 100000; ! number of samples to create
SEED = 52242; ! random seed
GENERATE = v1-v5 (3 p); ! specify the scale of the DVs; number of thresholds; probit (p)
CATEGORICAL = v1-v5; ! specify the variables that are (ordered) categorical
ANALYSIS:
PROCESSORS = 4 1; ! number of processors; number of threads
ESTIMATOR = WLSMV;
PARAMETERIZATION = THETA;
MODEL POPULATION: ! tell Mplus how to generate the population data; can use asterisks (*) and at symbols (@) interchangeably here, but they differ in the MODEL command (see below); I use the same symbol as in the MODEL command
dep BY v1-v5*.7; ! factor loadings
[dep@0]; ! set factor mean to 0
dep@1; ! set factor variance to 1 (standardize)
[v1$1*0.5] (v1t1); [v1$2*1.0] (v1t2); [v1$3*1.5] (v1t3); ! item thresholds for v1
[v2$1*0.5] (v2t1); [v2$2*1.0] (v2t2); [v2$3*1.5] (v2t3); ! item thresholds for v2
[v3$1*0.5] (v3t1); [v3$2*1.0] (v3t2); [v3$3*1.5] (v3t3); ! item thresholds for v3
[v4$1*0.0] (v4t1); [v4$2*0.5] (v4t2); [v4$3*1.0] (v4t3); ! item thresholds for v4
[v5$1*0.0] (v5t1); [v5$2*0.5] (v5t2); [v5$3*1.0] (v5t3); ! item thresholds for v5
v1-v5@1; ! item residual variances
MODEL: ! tell Mplus to estimate our model; asterisks (*) are free estimates with a starting value; at symbols (@) are fixed estimates
dep BY v1-v5*.7; ! factor loadings
[dep@0]; ! set factor mean to 0
dep@1; ! set factor variance to 1 (standardize)
[v1$1*0.5] (v1t1); [v1$2*1.0] (v1t2); [v1$3*1.5] (v1t3); ! item thresholds for v1
[v2$1*0.5] (v2t1); [v2$2*1.0] (v2t2); [v2$3*1.5] (v2t3); ! item thresholds for v2
[v3$1*0.5] (v3t1); [v3$2*1.0] (v3t2); [v3$3*1.5] (v3t3); ! item thresholds for v3
[v4$1*0.0] (v4t1); [v4$2*0.5] (v4t2); [v4$3*1.0] (v4t3); ! item thresholds for v4
[v5$1*0.0] (v5t1); [v5$2*0.5] (v5t2); [v5$3*1.0] (v5t3); ! item thresholds for v5
v1-v5@1; ! item residual variances
MODEL CONSTRAINT:
NEW (stdt stdt1 stdt2 stdt3 noninvt noninvt1 noninvt2 noninvt3 diff);
stdt1 = (v1t1 + v2t1 + v3t1) / 3;
stdt2 = (v1t2 + v2t2 + v3t2) / 3;
stdt3 = (v1t3 + v2t3 + v3t3) / 3;
noninvt1 = (v4t1 + v5t1) / 2;
noninvt2 = (v4t2 + v5t2) / 2;
noninvt3 = (v4t3 + v5t3) / 2;
stdt = (stdt1 + stdt2 + stdt3) / 3;
noninvt = (noninvt1 + noninvt2 + noninvt3) / 3;
diff = noninvt - stdt;
OUTPUT:
TECH9;
17.2 Multi-Group
Model
TITLE: Multi-Group Monte Carlo Simulation with Ordinal Items and Common Factor;
MONTECARLO:
NAMES = v1-v5; ! variable names
NGROUPS = 2; ! number of groups
NOBSERVATIONS = 500 300; ! number of participants in each sample
NREPS = 100000; ! number of samples to create
SEED = 52242; ! random seed
GENERATE = v1-v5 (3 p); ! specify the scale of the DVs; number of thresholds; probit (p)
CATEGORICAL = v1-v5; ! specify the variables that are (ordered) categorical
ANALYSIS:
PROCESSORS = 4 1; ! number of processors; number of threads
ESTIMATOR = WLSMV;
PARAMETERIZATION = THETA;
MODEL POPULATION: ! tell Mplus how to generate the population data; can use asterisks (*) and at symbols (@) interchangeably here, but they differ in the MODEL command (see below); I use the same symbol as in the MODEL command
dep BY v1-v5*.7; ! factor loadings
[dep@0]; ! set factor mean to 0
dep@1; ! set factor variance to 1 (standardize)
[v1$1*0.5] (v1t1g1); [v1$2*1.0] (v1t2g1); [v1$3*1.5] (v1t3g1); ! item thresholds for v1
[v2$1*0.5] (v2t1g1); [v2$2*1.0] (v2t2g1); [v2$3*1.5] (v2t3g1); ! item thresholds for v2
[v3$1*0.5] (v3t1g1); [v3$2*1.0] (v3t2g1); [v3$3*1.5] (v3t3g1); ! item thresholds for v3
[v4$1*0.5] (v4t1g1); [v4$2*1.0] (v4t2g1); [v4$3*1.5] (v4t3g1); ! item thresholds for v4
[v5$1*0.5] (v5t1g1); [v5$2*1.0] (v5t2g1); [v5$3*1.5] (v5t3g1); ! item thresholds for v5
v1-v5@1; ! item residual variances
MODEL POPULATION-g2: ! tell Mplus how to generate the population data for group 2; can use asterisks (*) and at symbols (@) interchangeably here, but they differ in the MODEL command (see below); I use the same symbol as in the MODEL command
!dep BY v1-v5*.7; ! factor loadings
![dep@0]; ! set factor mean to 0
!dep@1; ! set factor variance to 1 (standardize)
[v1$1*0.5] (v1t1g2); [v1$2*1.0] (v1t2g2); [v1$3*1.5] (v1t3g2); ! item thresholds for v1
[v2$1*0.5] (v2t1g2); [v2$2*1.0] (v2t2g2); [v2$3*1.5] (v2t3g2); ! item thresholds for v2
[v3$1*0.5] (v3t1g2); [v3$2*1.0] (v3t2g2); [v3$3*1.5] (v3t3g2); ! item thresholds for v3
[v4$1*0.0] (v4t1g2); [v4$2*0.5] (v4t2g2); [v4$3*1.0] (v4t3g2); ! item thresholds for v4
[v5$1*0.0] (v5t1g2); [v5$2*0.5] (v5t2g2); [v5$3*1.0] (v5t3g2); ! item thresholds for v5
!v1-v5@1; ! item residual variances
MODEL: ! tell Mplus to estimate our model; asterisks (*) are free estimates with a starting value; at symbols (@) are fixed estimates
dep BY v1-v5*.7; ! factor loadings
[dep@0]; ! set factor mean to 0
dep@1; ! set factor variance to 1 (standardize)
[v1$1*0.5] (v1t1g1); [v1$2*1.0] (v1t2g1); [v1$3*1.5] (v1t3g1); ! item thresholds for v1
[v2$1*0.5] (v2t1g1); [v2$2*1.0] (v2t2g1); [v2$3*1.5] (v2t3g1); ! item thresholds for v2
[v3$1*0.5] (v3t1g1); [v3$2*1.0] (v3t2g1); [v3$3*1.5] (v3t3g1); ! item thresholds for v3
[v4$1*0.5] (v4t1g1); [v4$2*1.0] (v4t2g1); [v4$3*1.5] (v4t3g1); ! item thresholds for v4
[v5$1*0.5] (v5t1g1); [v5$2*1.0] (v5t2g1); [v5$3*1.5] (v5t3g1); ! item thresholds for v5
v1-v5@1; ! item residual variances
MODEL g2: ! tell Mplus to estimate our model in group 2; asterisks (*) are free estimates with a starting value; at symbols (@) are fixed estimates
!dep BY v1-v5*.7; ! factor loadings
![dep@0]; ! set factor mean to 0
!dep@1; ! set factor variance to 1 (standardize)
[v1$1*0.5] (v1t1g2); [v1$2*1.0] (v1t2g2); [v1$3*1.5] (v1t3g2); ! item thresholds for v1
[v2$1*0.5] (v2t1g2); [v2$2*1.0] (v2t2g2); [v2$3*1.5] (v2t3g2); ! item thresholds for v2
[v3$1*0.5] (v3t1g2); [v3$2*1.0] (v3t2g2); [v3$3*1.5] (v3t3g2); ! item thresholds for v3
[v4$1*0.0] (v4t1g2); [v4$2*0.5] (v4t2g2); [v4$3*1.0] (v4t3g2); ! item thresholds for v4
[v5$1*0.0] (v5t1g2); [v5$2*0.5] (v5t2g2); [v5$3*1.0] (v5t3g2); ! item thresholds for v5
!v1-v5@1; ! item residual variances
MODEL CONSTRAINT:
NEW (stdt1g1 stdt2g1 stdt3g1 stdt1g2 stdt2g2 stdt3g2
nonit1g1 nonit2g1 nonit3g1 nonit1g2 nonit2g2 nonit3g2
stdtg1 stdtg2 nonitg1 nonitg2 diffwg diffbg);
stdt1g1 = (v1t1g1 + v2t1g1 + v3t1g1) / 3;
stdt2g1 = (v1t2g1 + v2t2g1 + v3t2g1) / 3;
stdt3g1 = (v1t3g1 + v2t3g1 + v3t3g1) / 3;
stdt1g2 = (v1t1g2 + v2t1g2 + v3t1g2) / 3;
stdt2g2 = (v1t2g2 + v2t2g2 + v3t2g2) / 3;
stdt3g2 = (v1t3g2 + v2t3g2 + v3t3g2) / 3;
nonit1g1 = (v4t1g1 + v5t1g1) / 2;
nonit2g1 = (v4t2g1 + v5t2g1) / 2;
nonit3g1 = (v4t3g1 + v5t3g1) / 2;
nonit1g2 = (v4t1g2 + v5t1g2) / 2;
nonit2g2 = (v4t2g2 + v5t2g2) / 2;
nonit3g2 = (v4t3g2 + v5t3g2) / 2;
stdtg1 = (stdt1g1 + stdt2g1 + stdt3g1) / 3;
stdtg2 = (stdt1g2 + stdt2g2 + stdt3g2) / 3;
nonitg1 = (nonit1g1 + nonit2g1 + nonit3g1) / 3;
nonitg2 = (nonit1g2 + nonit2g2 + nonit3g2) / 3;
diffwg = nonitg2 - stdtg2; ! difference within group
diffbg = nonitg2 - nonitg1; ! difference between groups
OUTPUT:
TECH9;
18 Session Info
sessionInfo()
R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.5 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
[4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
time zone: UTC
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] digest_0.6.37 R6_2.5.1 fastmap_1.2.0 xfun_0.49
[5] cachem_1.1.0 knitr_1.49 htmltools_0.5.8.1 rmarkdown_2.29
[9] lifecycle_1.0.4 cli_3.6.3 sass_0.4.9 jquerylib_0.1.4
[13] compiler_4.4.2 tools_4.4.2 evaluate_1.0.1 bslib_0.8.0
[17] yaml_2.3.10 rlang_1.1.4 jsonlite_1.8.9
11 Comments