Skip to contents

Performs a mixture clustering based on the structural parameters (i.e., regressions) of a SEM model. The estimation is done in a step-wise fashion and uses an expectation-maximization (EM) algorithm in the second step.

Usage

mmgsem(
  dat,
  S1 = NULL,
  S2 = NULL,
  s1_type = "lavaan",
  group,
  nclus,
  seed = NULL,
  userStart = NULL,
  s1_fit = NULL,
  max_it = 10000L,
  nstarts = 20L,
  printing = FALSE,
  partition = "hard",
  endogenous_cov = TRUE,
  endo_group_specific = TRUE,
  sam_method = "local",
  meanstr = FALSE,
  rescaling = F,
  only_slow = FALSE,
  ...
)

Arguments

dat

Data frame containing observed variables and a grouping variable..

S1

Step 1 (measurement model) specification using lavaan syntax. Can be a list of strings determing the number of measurement blocks (e.g., one string for the MM of factor 1, and a second string for the MM of factor 2). If s1_type = "mplus", S1 must be written in mplus syntax.

S2

Step 2 (structural model) specification using lavaan syntax.

s1_type

String. Determines which model is used when estimating step 1. Can be "lavaan" (CFA), "blavaan" (BCFA), or "mplus" (ML-CFA).

group

Name of the grouping variable (as a character string).

nclus

Integer. Number of clusters to be estimated in Step 2.

seed

Optional. Random seed for replicable results.

userStart

Optional. A user-defined cluster membership matrix (dimensions: number of groups × number of clusters) with binary values (1 or 0; 1 indicates cluster membership). To be used when the user has prior knowledge about the data. There must be only one 1 for each row. Skips random starts. Example for 6 groups and 2 clusters:

                              [,1] [,2]
                        [1,]    1    0
                        [2,]    1    0
                        [3,]    1    0
                        [4,]    0    1
                        [5,]    0    1
                        [6,]    0    1

s1_fit

Optional. A fitted model object for Step 1. Can be from lavaan (CFA), blavaan (BCFA), or MplusAutomation (ML-CFA).

max_it

Maximum number of iterations for Step 2 (default = 10000).

nstarts

Number of random starts for Step 2 (default = 20)..

printing

Logical. If TRUE, prints progress messages during estimation.

partition

Initialisation partition for random starts: "hard" (default) or "soft".

endogenous_cov

Logical. If TRUE (default), residual covariances among purely endogenous latent variables are estimated. If FALSE, they are fixed to 0 and only the residual variances are estimated.

endo_group_specific

Logical. If TRUE (default), residual covariances are group- and cluster-specific (i.e., they are estimated for every group-cluster combination). If FALSE, they are cluster-specific (i.e., they are fixed to be equal across groups within a cluster). Note that, if FALSE, the residual covariances will also influence the clustering.

sam_method

either "local" or "global. Follows local and global approaches from the SAM method. GLOBAL NOT FUNCTIONAL YET.

meanstr

Logical. If TRUE, includes the mean structure in the model (e.g., for scalar invariance).

rescaling

Only used when data is ordered. By default, MMGSEM uses the marker variable scaling approach. But identification constraints with ordinal data (by default) are handled by standardizing the factors' variance in the first step. The rescaling argument (either T or F) rescales the factor variances and loadings to the marker variable scaling before running step 2. It is set to T by default (rescaling happens). If set to F, the factor variances are kept fixed to 1.

only_slow

Logical. If TRUE, uses the slower Step 2 estimation implementation.

...

MMGSEM relies on lavaan for the estimation of the first step (i.e., CFA). If needed, the users can pass any lavaan argument to MMGSEM and it will be considered when estimating the CFA. For instance, std.lv if users want standardized latent variables, group.equal for constraints, group.partial for non-invariances, etc.

OUTPUT:

Value

The function will return a list with the following results:

posteriors: A groups × clusters matrix of posterior membership probabilities.

modal_post: A hard classification matrix indicating the most likely cluster for each group.

final_fit: Lavaan fit of the best and final model (not useful, only for testing purposes).

MM: Fitted measurement model (Step 1; i.e., cfa, bcfa, or ml-cfa). Returns the user-supplied model if provided.

param: A list of model parameters, including lambda_gs, theta_gs, beta_ks, psi_gks, and cov_eta.

logLik: A list of log-likelihood values: final model (only Step 2), random starts, and full model (Step 1 + Step 2).

model_sel: Model selection metrics such as BIC, AIC, and ICL.

sample.stats: Observed sample covariance matrices.

NrPar: A list containing the number of parameters.

N_gs: The sample size per group.

nstarts: The number of random starts used in step 2.

ngroups: Total number of groups.

iter: The number of iterations needed to reach convergence (from the best random start).

R2: A matrix containing the explained variance of each endogenous latent variable per group.