StepMix
A Python package for latent class analysis and clustering of continuous and categorical data, with support for missing values. Various stepwise estimation methods are available for models with measurement and structural components. Largely based on Bakk & Kuha, 2018.
Install
You can install StepMix with pip, preferably in a virtual environment :
pip install stepmix
Tutorials
Detailed tutorials are available in notebooks :
- Latent Class Analysis with StepMix :
an in-depth look at how latent class models can be defined with StepMix. The tutorial uses the Iris Dataset as an example
and covers :
- Continuous LCA models;
- Binary LCA models;
- Categorical LCA models;
- Mixed LCA models (continuous and categorical data);
- Missing Values.
- Stepwise Estimation with StepMix :
a tutorial demonstrating how to define measurement and structural models. The tutorial discusses:
- LCA models with response variables;
- LCA models with covariates;
- 1-step, 2-step and 3-step estimation;
- Corrections and other options for 3-step estimation.
- Model Selection :
a short tutorial discussing:
- Selecting the number of latent classes (
n_components); - Comparing models with AIC and BIC.
- Selecting the number of latent classes (
- Parameters, Bootstrapping and CI :
a tutorial discussing how to:
- Access StepMix parameters;
- Bootstrap StepMix estimators;
- Quickly plot confidence intervals.
Quickstart
A simple example for 3-step estimation on simulated data :
from stepmix.datasets import data_bakk_response
from stepmix.stepmix import StepMix
# Soft 3-step
X, Y, _ = data_bakk_response(n_samples=1000, sep_level=.9, random_state=42)
model = StepMix(n_components=3, n_steps=3, measurement='bernoulli', structural='gaussian_unit', assignment='soft',
random_state=42)
model.fit(X, Y)
print(model.score(X, Y)) # Average log-likelihood
# Equivalently, each step can be performed individually. See the code of the fit method for details.
model = StepMix(n_components=3, measurement='bernoulli', structural='gaussian_unit', random_state=42)
model.em(X) # Step 1
probs = model.predict_proba(X) # Step 2
model.m_step_structural(probs, Y) # Step 3
print(model.score(X, Y))
1-step and 2-step estimation are simply a matter of changing of the n_steps argument. Additionally, some bias correction
methods are available for 3-step estimation.
References
-
Bolck, A., Croon, M., and Hagenaars, J. Estimating latent structure models with categorical variables: One-step versus three-step estimators. Political analysis, 12(1): 3–27, 2004.
-
Vermunt, J. K. Latent class modeling with covariates: Two improved three-step approaches. Political analysis, 18 (4):450–469, 2010.
-
Bakk, Z., Tekle, F. B., and Vermunt, J. K. Estimating the association between latent class membership and external variables using bias-adjusted three-step approaches. Sociological Methodology, 43(1):272–311, 2013.
-
Bakk, Z. and Kuha, J. Two-step estimation of models between latent classes and external variables. Psychometrika, 83(4):871–892, 2018
Metadata
Release files for stepmix 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| stepmix-0.4.0.tar.gz | 46.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| stepmix-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 82.1 kB
Release files / stepmix-0.4.0.tar.gz
| Download URL | stepmix-0.4.0.tar.gz |
|---|---|
| Size | 46.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e10a6b4ea57938da9a5c45727635e0e355ebd73bf4e4b381e1ccbf6dbe4a2d4a
|
|
BLAKE2b-256 checksum How to use checksums |
b874c14705907a18cffff35192d66654e57dd5364e63d3d370308d196deb6ed2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.28.1
|
Release files / stepmix-0.4.0-py3-none-any.whl
| Download URL | stepmix-0.4.0-py3-none-any.whl |
|---|---|
| Size | 36.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dbe94053d815749b09c689cfb57a88fbc8c96e095fd4dd953a25708297ab91a7
|
|
BLAKE2b-256 checksum How to use checksums |
709b639b20619d0a08f2efa16bc60d22313ce1766176aa0632e4ba06e559f9e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.28.1
|