Skip to contents

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 (or level: within) and level: 2 (or level: between) blocks, see the details and examples.

data

dataset

estimator

estimator argument passed to Mplus. Bayesian estimation is available using estimator = "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. If NULL (default) it is chosen based on the model: "twolevel" for multilevel models, "complex" if cluster is specified, and "general" otherwise. "random" is added if the model contains interaction effects or random slopes.

algorithm

algorithm argument passed to Mplus. If NULL (default) it is set to "integration" for models with interaction effects (unless estimator = "bayes"), otherwise it is left to Mplus.

processors

processors argument passed to Mplus.

integration

integration argument passed to Mplus. Only used if algorithm = "integration".

analysis.options

Additional options passed to the ANALYSIS command of Mplus, as a named list (or character vector). E.g., list(BITERATIONS = "10000 (2000)", CHAINS = 4, BSEED = 123) for estimator = "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_item as the choose argument.

rcs.scale.corrected

Should reliability-corrected items be scale-corrected? If TRUE reliability-corrected single items are corrected for differences in factor loadings between the items. Default is TRUE.

output.std

Should STANDARDIZED be added to OUTPUT? It is ignored if Mplus doesn't support standardized estimates for the model (e.g., TYPE = TWOLEVEL RANDOM with a frequentist estimator).

categorical

categorical argument passed to Mplus.

within

Variables which should be declared as WITHIN variables in multilevel models. If NULL (default) all observed variables which only appear in the within (level: 1) model are declared as WITHIN variables.

between

Variables which should be declared as BETWEEN variables in multilevel models. If NULL (default) all observed variables which only appear in the between (level: 2) model are declared as BETWEEN variables.

cleanup

Should the Mplus files (.inp, .dat and .out) created during estimation be deleted when modsem_mplus() exits? Default is FALSE, meaning the files are kept in the working directory.

...

arguments passed to other functions

Value

modsem_mplus object

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)
}
# }