surveymixr implements growth mixture modeling (GMM) for longitudinal data with full integration of complex survey design features including stratification, clustering, and probability weights. This package fills a critical gap in R’s statistical capabilities by enabling analyses of large-scale longitudinal surveys (e.g., Millennium Cohort Study, Add Health, NLSY) that were previously only possible in proprietary software like Mplus.
📖 Read the complete User Manual for comprehensive documentation covering all features, workflows, and best practices.
# Install from CRAN (once published)
install.packages("surveymixr")
# Or install development version from GitHub
# install.packages("devtools")
devtools::install_github("siyangni/surveymixr")
library(surveymixr)
# Load simulated Millennium Cohort Study-like data
data(mcs_simulated)
# Fit 3-class growth mixture model with complex 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 trajectories
plot(fit, type = "trajectories")
# Check convergence diagnostics
diagnose_convergence(fit)
# Compare 1-5 class models with BLRT
selection <- gmm_select(
data = mcs_simulated,
id = "id",
time = "age",
outcome = "selfcontrol",
classes = 1:5,
strata = "stratum",
cluster = "psu",
weights = "weight",
criteria = c("BIC", "BLRT", "entropy"),
blrt_samples = 100,
starts = 200,
cores = 4
)
print(selection)
# Analyze auxiliary variables with classification uncertainty correction
r3step_results <- r3step(
gmm_object = fit,
distal_vars = c("academic_achievement", "delinquency"),
data = mcs_simulated,
method = "BCH"
)
summary(r3step_results)
Existing R packages have significant limitations:
| Feature | surveymixr | lcmm | flexmix | lavaan | openmx |
|---|---|---|---|---|---|
| Growth mixture models | ✓ | ✓ | Partial | ✗ | ✗ |
| Complex survey design | ✓ | ✗ | ✗ | Partial | ✗ |
| Stratification + clustering | ✓ | ✗ | ✗ | ✗ | ✗ |
| Probability weights | ✓ | ✗ | ✗ | ✗ | ✗ |
| BLRT implementation | ✓ | ✗ | ✗ | ✗ | ✗ |
| R3STEP method | ✓ | ✗ | ✗ | ✗ | ✗ |
| 1000+ random starts | ✓ | ✗ | ✗ | ✗ | ✗ |
surveymixr is the only R package that combines growth mixture modeling with full complex survey design features.
A comprehensive, unified guide covering:
Specialized topics are covered in additional vignettes:
vignette("surveymixr-intro"))vignette("technical-details"))vignette("r3step-analysis"))vignette("mplus-validation"))After package installation, view all vignettes with:
browseVignettes("surveymixr")
If you use surveymixr in your research, please cite:
Ni, S. (2025). surveymixr: An Open-Source R Package for Growth Mixture
Modeling with Complex Survey Design.
GPL-3
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.