A wrapper to select the number of clusters for MMG-SEM. By default it
estimates cross-sectional models with mmgsem(). If time is supplied, it
fits longitudinal models with lmmgsem() and reuses the measurement
invariance fit across candidate cluster counts.
Usage
ModelSelection(
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,
time = NULL,
s2_fast = TRUE,
mi_method = c("group_violations", "test_statistic"),
mi_alpha = 0.05,
mi_d_cfi_threshold = 0.01,
mi_max_iter = 20L,
mi_fit_indices = c("chisq", "df", "pvalue", "cfi", "rmsea", "srmr"),
mi_specific_noninv = FALSE,
...
)Arguments
- dat
Data frame containing observed variables and a grouping variable..
- S1
Step 1 (measurement model) specification. Can be omitted when
s1_fitis supplied. In cross-sectional mode it may be lavaan syntax, or a list of strings for multiple measurement blocks.- 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 in
dat.- nclus
Integer vector of length two. Determines the range of cluster solutions to estimate. It must contain the lower and upper boundaries of the models the user wants to estimate. For instance, nclus = c(1, 6) estimates models from 1 to 6 clusters.
- 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:
- s1_fit
Optional fitted Step 1 model. In longitudinal mode, this must be a lavaan multigroup fit with one group per group-time cell. In cross-sectional mode it may also be a blavaan or MplusAutomation fit. When omitted,
ModelSelection()computes and reuses the fit.- 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.
- time
Optional name of a time variable. When supplied, fit longitudinal models with
lmmgsem().- s2_fast
If
timeis supplied, use the fast longitudinal Step 2 estimator when TRUE and the slow estimator when FALSE.- mi_method
Score-test selection rule:
"group_violations"or"test_statistic"; used whentimeis supplied.- mi_alpha
Significance level for longitudinal score tests.
- mi_d_cfi_threshold
Maximum configural-to-metric CFI difference in the longitudinal invariance analysis.
- mi_max_iter
Maximum iterations per slice in the longitudinal invariance analysis.
- mi_fit_indices
Fit indices returned by the longitudinal invariance analysis.
- mi_specific_noninv
If
TRUE, allow non-invariance for specific group-time pairs.- ...
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.
Value
Overview: Matrix. It contains the results of all the model selection measures for each model.
Models: List containing the separate mmgsem() results, or
lmmgsem() results when time is supplied.
Details
In longitudinal mode, every group must have data at all time points and at least two time points must be present. The longitudinal information criteria use the sequence-level factor likelihood and marginal state entropy. The observed and factor likelihood columns are equal because a separate indicator-level longitudinal likelihood is not calculated. Convex-hull scores are unavailable when fewer than three cluster counts are fitted. Parameter counts include free measurement parameters, group-time-specific exogenous and endogenous covariance parameters, per-state regression parameters, and initial/transition probabilities.