Fits growth mixture models for longitudinal data with full integration of complex survey design features including stratification, clustering (PSUs), and probability weights. Implements the EM algorithm with sandwich standard errors for survey-adjusted inference.
Usage
gmm_survey(
data,
id,
time,
outcome,
n_classes = 2,
growth_model = "linear",
strata = NULL,
cluster = NULL,
weights = NULL,
nest = TRUE,
outcome_type = "continuous",
fixed_variances = FALSE,
fixed_timescores = TRUE,
predictors = NULL,
distal = NULL,
auxiliary = NULL,
starts = 500,
convergence = 1e-06,
max_iter = 1000,
cores = 1,
verbose = TRUE,
keep_data = FALSE,
...
)Arguments
- data
Data frame in long format containing repeated measurements
- id
Character string specifying the individual ID variable name
- time
Character string specifying the time variable name
- outcome
Character string specifying the outcome variable name
- n_classes
Integer number of latent classes (default: 2)
- growth_model
Character string specifying growth model type:
"linear"(default),"quadratic","nonlinear", or"free_basis"- strata
Character string specifying stratification variable (optional)
- cluster
Character string specifying cluster/PSU variable (optional)
- weights
Character string specifying sampling weights variable (optional)
- nest
Logical indicating nested clustering (default: TRUE)
- outcome_type
Character string:
"continuous"(default),"count","binary", or"ordinal"- fixed_variances
Logical, should residual variances be constrained equal across classes? (default: FALSE)
- fixed_timescores
Logical, should time scores be equal across classes? (default: TRUE)
- predictors
Character vector of time-varying predictor variable names (not yet implemented)
- distal
Character vector of distal outcome variable names (use with
r3step()function)- auxiliary
Character vector of auxiliary variable names for class membership prediction
- starts
Integer number of random starts (default: 500)
- convergence
Numeric convergence criterion (default: 1e-6)
- max_iter
Integer maximum number of EM iterations (default: 1000)
- cores
Integer number of CPU cores for parallel processing (default: 1)
- verbose
Logical, print progress messages? (default: TRUE)
- keep_data
Logical, store data in output object? (default: FALSE)
- ...
Additional arguments (reserved for future use)
Value
An S4 object of class SurveyMixr containing:
- parameters
Class-specific growth parameters (means, variances)
- class_proportions
Weighted and unweighted class proportions
- posterior_probs
Posterior probabilities for each individual
- standard_errors
Survey-adjusted standard errors
- fit_indices
AIC, BIC, aBIC, entropy, log-likelihood
- convergence_info
Convergence diagnostics from random starts
- survey_design
Survey design information
Details
This function implements growth mixture modeling with full survey design integration, a feature combination not available in other R packages. The implementation uses:
EM algorithm with survey weight integration in the likelihood
Multiple random starts to avoid local maxima
Sandwich standard errors for stratification and clustering
FIML for missing data
The function automatically converts data from long to wide format internally for computational efficiency. Survey weights are normalized to sum to the sample size.
For model selection across different numbers of classes, see
gmm_select. For analyzing auxiliary variables with
classification uncertainty correction, see r3step.
References
Muthén, B. (2004). Latent variable analysis: Growth mixture modeling and related techniques for longitudinal data. In D. Kaplan (Ed.), Handbook of quantitative methodology for the social sciences (pp. 345-368). Sage Publications.
Asparouhov, T., & Muthén, B. (2014). Auxiliary variables in mixture modeling: Three-step approaches using Mplus. Structural Equation Modeling: A Multidisciplinary Journal, 21(3), 329-341.
Lumley, T. (2010). Complex surveys: A guide to analysis using R. John Wiley & Sons.
Examples
if (FALSE) { # \dontrun{
# Load simulated data
data(mcs_simulated)
# Fit 3-class model with survey design
fit <- gmm_survey(
data = mcs_simulated,
id = "id",
time = "age",
outcome = "selfcontrol",
n_classes = 3,
growth_model = "linear",
strata = "stratum",
cluster = "psu",
weights = "weight",
starts = 500,
cores = 4
)
# View results
summary(fit)
plot(fit, type = "trajectories")
# Check convergence
diagnose_convergence(fit)
} # }