Dynamically creates a batch of mixture models, with intelligent defaults. See Details for more information.
Arguments
- model
Syntax for the model; either a character string, or a list of character strings, or a list of
mxModel
objects. See Details.- classes
A vector of integers, indicating which class solutions to generate. Defaults to 1L. E.g.,
classes = 1:6
,classes = c(1:4, 6:8)
.- data
The data.frame to be used for model fitting.
- run
Logical, whether or not to run the model. If
run = TRUE
, the function callsmixture_starts
andrun_mx
.- ...
Additional arguments, passed to functions.
Value
Returns an OpenMx::mxModel()
.
Details
Model syntax can be specified in three ways, for ease of use and flexibility:
An atomic character string with lavaan syntax. Within this syntax, the character string
{C}
is dynamically substituted with the correct class number usinglsub
, for example to set unique parameter labels for each class, or to specify equality constraints. E.g.,x ~ m{C}*1
will be expanded tox ~ m1*1
andx ~ m2*1
whenclasses = 2
. The resulting syntax for each class will be converted to anmxModel
usingas_ram
.A list of character strings with lavaan syntax. Each item of the list will be converted to a class-specific
mxModel
usingas_ram
.A list of
mxModel
objects, specified by the user.
References
Van Lissa, C. J., Garnier-Villarreal, M., & Anadria, D. (2023). Recommended Practices in Latent Class Analysis using the Open-Source R-Package tidySEM. Structural Equation Modeling. doi:10.1080/10705511.2023.2250920
Examples
if (FALSE) { # \dontrun{
# Example 1: Dynamic model generation using {C}
df <- iris[, 1, drop = FALSE]
names(df) <- "x"
mx_mixture(model = "x ~ m{C}*1
x ~~ v{C}*x", classes = 1, data = df)
# Example 2: Manually specified class-specific models
df <- iris[1:2]
names(df) <- c("x", "y")
mx_mixture(model = list("y ~ a*x",
"y ~ b*x"),
meanstructure = TRUE,
data = df) -> res
# Example 3: Latent growth model
df <- empathy[1:6]
mx_mixture(model = "i =~ 1*ec1 + 1*ec2 + 1*ec3 +1*ec4 +1*ec5 +1*ec6
s =~ 0*ec1 + 1*ec2 + 2*ec3 +3*ec4 +4*ec5 +5*ec6",
classes = 2,
data = df) -> res
} # }