mx_mixture {tidySEM} | R Documentation |
Estimate mixture models using OpenMx
Description
Dynamically creates a batch of mixture models, with intelligent defaults. See Details for more information.
Usage
mx_mixture(model, classes = 1L, data = NULL, run = TRUE, ...)
Arguments
model |
Syntax for the model; either a character string, or a list of
character strings, or a list of |
classes |
A vector of integers, indicating which class solutions to
generate. Defaults to 1L. E.g., |
data |
The data.frame to be used for model fitting. |
run |
Logical, whether or not to run the model. If |
... |
Additional arguments, passed to functions. |
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.
Value
Returns an mxModel
.
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
## Not run:
# 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
## End(Not run)