Code
library("MplusAutomation")
prepareMplusData(
mydata,
file.path(path, "/GitHub/Project_Name/Data/mplusdata.dat"))MplusMplus
Mplus is software for structural equation modeling. A summary of the Mplus language syntax is here (archived at: https://perma.cc/962G-QUEG). The Mplus User’s Guide is located here (archived at: https://perma.cc/W39W-NRGH).
To prepare the data in R for use in Mplus:
library("MplusAutomation")
prepareMplusData(
mydata,
file.path(path, "/GitHub/Project_Name/Data/mplusdata.dat"))!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!! 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;
TITLE: INSERT TITLE HERE
DATA:
FILE = "C:/[insert_filepath]/filename.dat";
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
CLUSTER = ID;
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
CATEGORICAL = x1 x2;
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
COUNT = x1 x2;
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
IDVARIABLE = ID;
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;
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID x1 x2 y1;
AUXILIARY = age;
VARIABLE:
NAMES = ID wt age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
WEIGHT = wt;
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;
TYPE = COMPLEXTYPE = TWOLEVELTYPE = EFATYPE = MIXTUREANALYSIS:
ESTIMATOR = MLR;
MLR: for likert/continuous dataWLSMV: for ordinal/categorical dataBAYESBOOTSTRAP = 2000; ! insert number of bootstrap draws
STARTS = 20; ! insert number of initial stage starts and number of final stage optimizations
To estimate a model with low covariance coverage, lower the COVERAGE value under the ANALYSIS section:
ANALYSIS:
COVERAGE = 0;
ANALYSIS:
TYPE = EFA 1 5; ! extract 1-5 factors
ROTATION = GEOMIN;
ANALYSIS:
TYPE = EFA 1 5; ! extract 1-5 factors
ROTATION = VARIMAX;
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
MODEL:
latent1 BY x1 x2 x3;
Regress outcome variable on predictor variable(s):
MODEL:
y1 ON x1 x2;
MODEL:
x1 WITH x2;
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
Freely estimate:
MODEL:
[x1];
Fix to zero:
MODEL:
[x1@0];
Freely estimate:
MODEL:
x1;
Fix to one:
MODEL:
x1@1;
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;
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;
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;
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;
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;
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;
MODEL:
latent1 BY x1@1 x2 x3;
[latent1@0];
latent1@1;
To set two parameters to be equal, provide the same parameter label for each 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;
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;
PLOT:
SERIES =
ext36 (36) ext45 (45) ext54 (54) ext63 (63)
ext72 (72) ext81 (81) ext90 (90);
TYPE = PLOT3;
OUTLIERS =
MAHALANOBIS ! Mahalanobis distance and its p-value
LOGLIKELIHOOD ! Loglikelihood contribution
INFLUENCE ! Loglikelihood distance influence measure
COOKS; ! Cook's D parameter estimate influence measure
SAVEDATA:
FILE = "C:/[insert_filepath]/filename.dat";
SAVE =
FSCORES ! Factor scores
LOGLIKELIHOOD ! Loglikelihood contribution from each observation
INFLUENCE ! Loglikelihood distance influence measure (Cook & Weisberg, 1982) for each observation
COOKS; !Cook's D (Cook, 1977) for each observation
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;
VARIABLE:
NAMES = id y0 y1 y2 y3 y4 x;
USEVARIABLES = y0 y1 y2 y3 y4 x;
ANALYSIS:
TYPE = RANDOM;
MODEL:
i s q | y0 y1 y2 y3 y4 AT t0 t1 t2 t3 t4; ! intercept, linear slope, quadratic slopes
i s q ON x;
Unequally spaced time points can be accounted for using the TSCORES option.
https://stats.oarc.ucla.edu/mplus/faq/how-can-i-run-a-growth-model-in-wide-form-with-unequally-spaced-time-points-tscore/ (archived at https://perma.cc/Z7QY-TL6W)
VARIABLE:
NAMES = id t0 t1 t2 t3 t4 y0 y1 y2 y3 y4 x;
USEVARIABLES = t0 t1 t2 t3 t4 y0 y1 y2 y3 y4 x;
TSCORES = t0 t1 t2 t3 t4;
ANALYSIS:
TYPE = RANDOM;
MODEL:
i s q | y1@0 y2@1 y3@2 y4@3; ! intercept, linear slope, quadratic slope
i s q ON x;
VARIABLE:
NAMES = id y1 y2 y3 y4;
USEVARIABLES = y1 y2 y3 y4;
IDVARIABLE = id;
CLASSES = c(3); ! 3 latent classes
MISSING = .;
ANALYSIS:
TYPE = MIXTURE;
ESTIMATOR = MLR;
STARTS = 500 20;
STITERATIONS = 20;
MODEL:
%OVERALL%
i s q | y1@0 y2@1 y3@2 y4@3; ! intercept, linear slope, quadratic slope
i@0; s@0; q@0; ! fix variances to zero (LCGA assumption)
%c#1%
[i s q]; ! freely estimate class-specific means
%c#2%
[i s q];
%c#3%
[i s q];
OUTPUT:
standardized TECH1 TECH4 TECH8 TECH11 TECH14;
PLOT:
TYPE = PLOT3;
SERIES = y1(0) y2(1) y3(2) y4(3);
SAVEDATA:
FILE = lcga_3class_prob.dat;
SAVE = CPROBABILITIES;
Run models in batch via R:
library("MplusAutomation")
runModels(
file.path(path, "/GitHub/Project_Name/Analyses/Mplus/"),
recursive = TRUE,
replaceOutfile = "always",
showOutput = TRUE)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;
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;
R version 4.5.2 (2025-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.3 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.26.so; LAPACK version 3.12.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] htmlwidgets_1.6.4 compiler_4.5.2 fastmap_1.2.0 cli_3.6.5
[5] tools_4.5.2 htmltools_0.5.9 otel_0.2.0 yaml_2.3.12
[9] rmarkdown_2.30 knitr_1.51 jsonlite_2.0.0 xfun_0.55
[13] digest_0.6.39 rlang_1.1.6 evaluate_1.0.5
---
title: "Mplus"
output:
html_document:
code_folding: show
---
# Overview of `Mplus`
[`Mplus`](https://www.statmodel.com) is software for [structural equation modeling](sem.qmd).
A summary of the [`Mplus`](https://www.statmodel.com) language syntax is [here](https://www.statmodel.com/language.html) (archived at: <https://perma.cc/962G-QUEG>).
The [Mplus User's Guide](https://www.statmodel.com/html_ug.shtml) is located [here](https://www.statmodel.com/download/usersguide/MplusUserGuideVer_8.pdf) (archived at: <https://perma.cc/W39W-NRGH>).
# Prepare Data {#prepareData}
To prepare the data in `R` for use in `Mplus`:
```{r}
#| eval: false
library("MplusAutomation")
prepareMplusData(
mydata,
file.path(path, "/GitHub/Project_Name/Data/mplusdata.dat"))
```
# Model Example {#example}
```
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!! 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;
```
# Model Title {#modelTitle}
```
TITLE: INSERT TITLE HERE
```
# Read Data {#readData}
```
DATA:
FILE = "C:/[insert_filepath]/filename.dat";
```
# Variables {#variables}
## Specify Variables {#specifyVariables}
```
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
CLUSTER = ID;
```
## Categorical Variables {#categoricalVariables}
```
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
CATEGORICAL = x1 x2;
```
## Count Variables {#countVariables}
```
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
COUNT = x1 x2;
```
## ID Variable {#idVariable}
```
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
IDVARIABLE = ID;
```
## Cluster Variable {#clusterVariable}
There are multiple ways of accounting for nested data in [structural equation modeling](sem.qmd).
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;
```
## Auxiliary Variables {#auxiliaryVariables}
```
VARIABLE:
NAMES = ID age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID x1 x2 y1;
AUXILIARY = age;
```
## Sampling Weight Variable {#samplingWeight}
```
VARIABLE:
NAMES = ID wt age x1 x2 x3 y1;
MISSING = .;
USEVARIABLES = ID age x1 x2 y1;
WEIGHT = wt;
```
## Multilevel Variables {#multilevelVariables}
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;
```
# Analysis {#analysis}
## Analysis Types {#analysisTypes}
- `TYPE = COMPLEX`
- `TYPE = TWOLEVEL`
- `TYPE = EFA`
- `TYPE = MIXTURE`
## Model Estimators {#estimators}
```
ANALYSIS:
ESTIMATOR = MLR;
```
- `MLR`: for likert/continuous data
- `WLSMV`: for ordinal/categorical data
- `BAYES`
## Bootstrap Draws {#bootstrap}
```
BOOTSTRAP = 2000; ! insert number of bootstrap draws
```
## Starts {#starts}
```
STARTS = 20; ! insert number of initial stage starts and number of final stage optimizations
```
## Low Covariance Coverage {#lowCovarianceCoverage}
To estimate a model with low covariance coverage, lower the `COVERAGE` value under the `ANALYSIS` section:
```
ANALYSIS:
COVERAGE = 0;
```
# Exploratory Factor Analysis {#efa}
## Oblique Rotation {#oblique}
```
ANALYSIS:
TYPE = EFA 1 5; ! extract 1-5 factors
ROTATION = GEOMIN;
```
## Orthogonal Rotation {#orthogonal}
```
ANALYSIS:
TYPE = EFA 1 5; ! extract 1-5 factors
ROTATION = VARIMAX;
```
# Bayesian SEM {#bayesian}
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
```
# Model {#model}
## Define Latent Variables {#latentVariables}
```
MODEL:
latent1 BY x1 x2 x3;
```
## Regression Paths {#regressionPaths}
Regress outcome variable on predictor variable(s):
```
MODEL:
y1 ON x1 x2;
```
## Covariance Paths {#covariancePaths}
```
MODEL:
x1 WITH x2;
```
## Indirect Effects {#indirectEffects}
```
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
```
## Means/Intercepts {#means}
Freely estimate:
```
MODEL:
[x1];
```
Fix to zero:
```
MODEL:
[x1@0];
```
## Variances {#variances}
Freely estimate:
```
MODEL:
x1;
```
Fix to one:
```
MODEL:
x1@1;
```
## Parameter Label {#parameterLabel}
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;
```
## Multigroup Model {#multigroup}
```
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;
```
## Multigroup Measurement Invariance {#measurementInvariance}
### Configural Invariance {#configuralInvariance}
```
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;
```
### Metric (Weak Factorial) Invariance {#metricInvariance}
```
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;
```
### Scalar (Strong Factorial) Invariance {#scalarInvariance}
```
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;
```
# Comments {#comments}
```
!This is a comment in Mplus
```
# Setting Parameter Constraints {#parameterConstraints}
## Freeing a Parameter {#freeParameter}
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;
```
## Constraing a Parameter {#constrainParameter}
```
MODEL:
latent1 BY x1@1 x2 x3;
[latent1@0];
latent1@1;
```
## Setting Two Parameters to be Equal {#equalParameters}
To set two parameters to be equal, provide the same [parameter label](#parameterLabel) for each parameter.
## Setting Lower and Upper Bounds on a Parameter {#parameterBounds}
To set lower and upper bounds on a parameter, you can assign the parameter a [parameter label](#parameterLabel).
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;
```
# Output {#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;
```
# Plot {#plot}
```
PLOT:
SERIES =
ext36 (36) ext45 (45) ext54 (54) ext63 (63)
ext72 (72) ext81 (81) ext90 (90);
TYPE = PLOT3;
OUTLIERS =
MAHALANOBIS ! Mahalanobis distance and its p-value
LOGLIKELIHOOD ! Loglikelihood contribution
INFLUENCE ! Loglikelihood distance influence measure
COOKS; ! Cook's D parameter estimate influence measure
```
# Save Data {#saveData}
```
SAVEDATA:
FILE = "C:/[insert_filepath]/filename.dat";
SAVE =
FSCORES ! Factor scores
LOGLIKELIHOOD ! Loglikelihood contribution from each observation
INFLUENCE ! Loglikelihood distance influence measure (Cook & Weisberg, 1982) for each observation
COOKS; !Cook's D (Cook, 1977) for each observation
```
# Multiple Imputation {#multipleImputation}
For examples of how to conduct [multiple imputation](multipleImputation.qmd) in [`Mplus`](https://www.statmodel.com), see [here](multipleImputation.qmd#mplus).
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;
```
# Latent Growth Curve Model {#lgcm}
## Equally Spaced Time Points {#equallySpaced}
```
VARIABLE:
NAMES = id y0 y1 y2 y3 y4 x;
USEVARIABLES = y0 y1 y2 y3 y4 x;
ANALYSIS:
TYPE = RANDOM;
MODEL:
i s q | y0 y1 y2 y3 y4 AT t0 t1 t2 t3 t4; ! intercept, linear slope, quadratic slopes
i s q ON x;
```
## Unequally Spaced Time Points (Individually Varying Times of Observation) {#tScores}
Unequally spaced time points can be accounted for using the `TSCORES` option.
<https://stats.oarc.ucla.edu/mplus/faq/how-can-i-run-a-growth-model-in-wide-form-with-unequally-spaced-time-points-tscore/> (archived at <https://perma.cc/Z7QY-TL6W>)
```
VARIABLE:
NAMES = id t0 t1 t2 t3 t4 y0 y1 y2 y3 y4 x;
USEVARIABLES = t0 t1 t2 t3 t4 y0 y1 y2 y3 y4 x;
TSCORES = t0 t1 t2 t3 t4;
ANALYSIS:
TYPE = RANDOM;
MODEL:
i s q | y1@0 y2@1 y3@2 y4@3; ! intercept, linear slope, quadratic slope
i s q ON x;
```
# Latent Class Growth Analysis {#lcga}
```
VARIABLE:
NAMES = id y1 y2 y3 y4;
USEVARIABLES = y1 y2 y3 y4;
IDVARIABLE = id;
CLASSES = c(3); ! 3 latent classes
MISSING = .;
ANALYSIS:
TYPE = MIXTURE;
ESTIMATOR = MLR;
STARTS = 500 20;
STITERATIONS = 20;
MODEL:
%OVERALL%
i s q | y1@0 y2@1 y3@2 y4@3; ! intercept, linear slope, quadratic slope
i@0; s@0; q@0; ! fix variances to zero (LCGA assumption)
%c#1%
[i s q]; ! freely estimate class-specific means
%c#2%
[i s q];
%c#3%
[i s q];
OUTPUT:
standardized TECH1 TECH4 TECH8 TECH11 TECH14;
PLOT:
TYPE = PLOT3;
SERIES = y1(0) y2(1) y3(2) y4(3);
SAVEDATA:
FILE = lcga_3class_prob.dat;
SAVE = CPROBABILITIES;
```
# Run Models in Batch {#runModels}
Run models in batch via `R`:
```{r}
#| eval: false
library("MplusAutomation")
runModels(
file.path(path, "/GitHub/Project_Name/Analyses/Mplus/"),
recursive = TRUE,
replaceOutfile = "always",
showOutput = TRUE)
```
# Monte Carlo Simulation/Power Analysis {#monteCarlo}
## Single Group Model {#monteCarloSingleGroup}
```
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;
```
## Multi-Group Model {#monteCarloMultigroup}
```
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;
```
# Session Info
```{r}
#| code-fold: true
sessionInfo()
```
11 Comments