Estimation latent interactions through Mplus
Usage
modsem_mplus(
model.syntax,
data,
estimator = "ml",
cluster = NULL,
type = NULL,
algorithm = NULL,
processors = 2,
integration = 15,
analysis.options = NULL,
rcs = FALSE,
rcs.choose = NULL,
rcs.scale.corrected = TRUE,
output.std = TRUE,
categorical = NULL,
within = NULL,
between = NULL,
cleanup = FALSE,
...
)Arguments
- model.syntax
lavaan/modsem syntax. Multilevel models can be specified using
level: 1(orlevel: within) andlevel: 2(orlevel: between) blocks, see the details and examples.- data
dataset
- estimator
estimator argument passed to
Mplus. Bayesian estimation is available usingestimator = "bayes", see the details.- cluster
cluster argument passed to
Mplus. Required for multilevel models. For single level models it is used to compute standard errors corrected for clustering (i.e.,TYPE = COMPLEX).- type
type argument passed to
Mplus. IfNULL(default) it is chosen based on the model:"twolevel"for multilevel models,"complex"ifclusteris specified, and"general"otherwise."random"is added if the model contains interaction effects or random slopes.- algorithm
algorithm argument passed to
Mplus. IfNULL(default) it is set to"integration"for models with interaction effects (unlessestimator = "bayes"), otherwise it is left toMplus.- processors
processors argument passed to
Mplus.- integration
integration argument passed to
Mplus. Only used ifalgorithm = "integration".- analysis.options
Additional options passed to the
ANALYSIScommand ofMplus, as a named list (or character vector). E.g.,list(BITERATIONS = "10000 (2000)", CHAINS = 4, BSEED = 123)forestimator = "bayes".- rcs
Should latent variable indicators be replaced with reliability-corrected single item indicators instead? See
relcorr_single_item. Not available for multilevel models.- rcs.choose
Which latent variables should get their indicators replaced with reliability-corrected single items? It is passed to
relcorr_single_itemas thechooseargument.- rcs.scale.corrected
Should reliability-corrected items be scale-corrected? If
TRUEreliability-corrected single items are corrected for differences in factor loadings between the items. Default isTRUE.- output.std
Should
STANDARDIZEDbe added toOUTPUT? It is ignored ifMplusdoesn't support standardized estimates for the model (e.g.,TYPE = TWOLEVEL RANDOMwith a frequentist estimator).- categorical
categorical argument passed to
Mplus.- within
Variables which should be declared as
WITHINvariables in multilevel models. IfNULL(default) all observed variables which only appear in the within (level: 1) model are declared asWITHINvariables.- between
Variables which should be declared as
BETWEENvariables in multilevel models. IfNULL(default) all observed variables which only appear in the between (level: 2) model are declared asBETWEENvariables.- cleanup
Should the
Mplusfiles (.inp,.datand.out) created during estimation be deleted whenmodsem_mplus()exits? Default isFALSE, meaning the files are kept in the working directory.- ...
arguments passed to other functions
Details
Interaction terms (e.g., X:Z) involving at least one latent variable are
specified using XWITH, whilst interaction terms between observed variables are
computed as product terms in the DEFINE command of Mplus.
If estimator = "bayes" the parameter table contains the posterior means
(est), posterior standard deviations (std.error), the one-tailed
p-values reported by Mplus (p.value), and the 95% credible
intervals (ci.lower and ci.upper). z.value is NA.
The number of iterations, chains etc. can be set using analysis.options.
In multilevel models random slopes are specified using the rv() modifier
in the within level model (e.g., Y ~ rv("s")*X), which is translated to
s | Y ON X; in Mplus. The random slope (s) is a latent variable
at the between level, where it can be used like any other latent variable. Note that
the fixed effect of a random slope is the mean (or intercept) of the random slope at
the between level.
Examples
# Theory Of Planned Behavior
m1 <- '
# Outer Model
X =~ x1 + x2
Z =~ z1 + z2
Y =~ y1 + y2
# Inner model
Y ~ X + Z + X:Z
'
# \dontrun{
# Check if Mplus is installed
run <- tryCatch({MplusAutomation::detectMplus(); TRUE},
error = \(e) FALSE)
if (run) {
est_mplus <- modsem_mplus(m1, data = oneInt)
summary(est_mplus)
}
# Multilevel model with a random slope, and a (within level) interaction
m2 <- '
level: 1
fw =~ y1 + y2 + y3
fw ~ rv("s")*x1 + x2 + x3 + x2:x3
level: 2
fb =~ y1 + y2 + y3
fb + s ~ w1 + w2
'
if (run) {
est_mplus_ml <- modsem_mplus(m2, data = lavaan::Demo.twolevel, cluster = "cluster")
summary(est_mplus_ml)
}
# }