Skip to contents

Fits a stepwise measurement-invariance model and then an HMM whose latent states represent clusters of groups over time. Each group must be observed at every time point, with at least two time points.

Usage

lmmgsem(
  dat,
  S1 = NULL,
  S2,
  group,
  time,
  nclus,
  seed = NULL,
  max_it = 10000L,
  nstarts = 20L,
  printing = FALSE,
  s2_fast = TRUE,
  s1_fit = NULL,
  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 the observed variables, group identifier, and time identifier.

S1

Measurement model in lavaan syntax. Required when s1_fit is not supplied.

S2

Structural model in lavaan syntax.

group

Name of the grouping variable in dat.

time

Name of the time variable in dat.

nclus

Number of latent states (clusters).

seed

Optional random seed for reproducibility.

max_it

Maximum number of EM iterations per random start.

nstarts

Number of random starts.

printing

If TRUE, print iteration progress.

s2_fast

If TRUE, use the fast Step 2 estimator; otherwise use the slow estimator.

s1_fit

Optional lavaan measurement-model fit with one group per group-time cell. Its group labels must match interaction(dat[[group]], dat[[time]], sep = ".Time"). If omitted, measurement invariance is estimated using compute_mi_long_stepwise_score().

mi_method

Method for selecting invariance violations: "group_violations" or "test_statistic".

mi_alpha

Significance level for the score tests.

mi_d_cfi_threshold

Maximum configural-to-metric CFI difference.

mi_max_iter

Maximum iterations in each stepwise invariance analysis.

mi_fit_indices

Fit indices returned by the invariance analysis.

mi_specific_noninv

If TRUE, allow non-invariance for specific group-time pairs; otherwise free loadings globally.

...

Additional arguments passed to lavaan's CFA fitting functions during the measurement-invariance analysis.

Value

A lmmgsem object containing time-specific posterior state probabilities, transition probabilities, model parameters, likelihoods, and model-selection criteria. Information criteria use the sequence-level factor likelihood and marginal posterior state entropy. Standard errors are not currently implemented. Parameter counts include free measurement parameters, group-time-specific exogenous and endogenous covariance parameters, per-state regression parameters, and initial/transition probabilities.