Skip to main content

A Python package for stepwise estimation of latent class models with measurement and structural components. The package can also be used to fit mixture models with various observed random variables.

Project description

StepMix

PyPI version Build Documentation Status Code style: black Downloads Downloads arXiv

For StepMixR, please refer to this repository.

A Python package following the scikit-learn API for generalized mixture modeling. The package supports categorical data (Latent Class Analysis) and continuous data (Gaussian Mixtures/Latent Profile Analysis). StepMix can be used for both clustering and supervised learning.

Additional features include:

  • Support for missing values through Full Information Maximum Likelihood (FIML);
  • Multiple stepwise Expectation-Maximization (EM) estimation methods based on pseudolikelihood theory;
  • Covariates and distal outcomes;
  • Parametric and non-parametric bootstrapping.

Reference

If you find StepMix useful, please consider citing our arXiv preprint:

@article{morin2023stepmix,
  title={StepMix: A Python Package for Pseudo-Likelihood Estimation of Generalized Mixture Models with External Variables},
  author={Morin, Sacha and Legault, Robin and Lalibert{\'e}, F{\'e}lix and Bakk, Zsuzsa and Gigu{\`e}re, Charles-{\'E}douard and de la Sablonni{\`e}re, Roxane and Lacourse, {\'E}ric},
  journal={arXiv preprint arXiv:2304.03853},
  year={2023}
}

Install

You can install StepMix with pip, preferably in a virtual environment:

pip install stepmix

Quickstart

A StepMix mixture using categorical variables on a preloaded data matrix. StepMix accepts either numpy.arrayor pandas.DataFrame. Categories should be integer-encoded and 0-indexed.

from stepmix.stepmix import StepMix

# Categorical StepMix Model with 3 latent classes
model = StepMix(n_components=3, measurement="categorical")
model.fit(data)

# Allow missing values
model_nan = StepMix(n_components=3, measurement="categorical_nan")
model_nan.fit(data_nan)

For binary data you can also use measurement="binary" or measurement="binary_nan". For continuous data, you can fit a Gaussian Mixture with diagonal covariances using measurement="continuous" or measurement="continuous_nan".

Set verbose=1 for a detailed output.

Please refer to the StepMix tutorials to learn how to combine continuous and categorical data in the same model.

Tutorials

Detailed tutorials are available in notebooks:

  1. Generalized Mixture Models with StepMix: an in-depth look at how mixture models can be defined with StepMix. The tutorial uses the Iris Dataset as an example and covers:
    1. Gaussian Mixtures (Latent Profile Analysis);
    2. Binary Mixtures (LCA);
    3. Categorical Mixtures (LCA);
    4. Mixed Categorical and Continuous Mixtures;
    5. Missing Values through Full-Information Maximum Likelihood.
  2. Stepwise Estimation with StepMix: a tutorial demonstrating how to define measurement and structural models. The tutorial discusses:
    1. LCA models with distal outcomes;
    2. LCA models with covariates;
    3. 1-step, 2-step and 3-step estimation;
    4. Corrections (BCH or ML) and other options for 3-step estimation;
    5. Putting it All Together: A Complete Model with Missing Values
  3. Model Selection:
    1. Selecting the number of components in a mixture model (n_components) with cross-validation;
    2. Selecting the number of components with the Parametric Bootstrapped Likelihood Ratio Test (BLRT);
    3. Fit indices: AIC, BIC and other metrics.
  4. Parameters, Bootstrapping and CI: a tutorial discussing how to:
    1. Access StepMix parameters;
    2. Bootstrap StepMix estimators;
    3. Quickly plot confidence intervals.
  5. Supervised and Semi-Supervised Learning with StepMix:
    1. Binary Classification;
    2. Multiclass Classification;
    3. Semi-Supervised Learning;
    4. Cross-Validation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stepmix-2.2.0.tar.gz (60.1 kB view details)

Uploaded Source

Built Distribution

stepmix-2.2.0-py3-none-any.whl (44.2 kB view details)

Uploaded Python 3

File details

Details for the file stepmix-2.2.0.tar.gz.

File metadata

  • Download URL: stepmix-2.2.0.tar.gz
  • Upload date:
  • Size: 60.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for stepmix-2.2.0.tar.gz
Algorithm Hash digest
SHA256 6edf94274c6489b99d77aa5bd3d6c60dcf6b5d9c41fc09d3b3a46efa9fbaeaf5
MD5 b3f925a290de31ce4f80a467fd776dbe
BLAKE2b-256 7f7ea091410313f6429f91bc85614970f199a59d976d78d2490018ff7b35999f

See more details on using hashes here.

File details

Details for the file stepmix-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: stepmix-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 44.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for stepmix-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09e5214ee428b4781cb643d8d79c6558c94e42b5575e28f3e773586d60bc0c04
MD5 b68922fbf2697718887afe5d2367cd5a
BLAKE2b-256 b0db28693aca30c3f1f8f15711ac7126aab90237114867b1e7fa64e2365268ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page