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

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 :

  1. 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 :
    1. Continuous LCA models;
    2. Binary LCA models;
    3. Categorical LCA models;
    4. Mixed LCA models (continuous and categorical data);
    5. Missing Values.
  2. Stepwise Estimation with StepMix : a tutorial demonstrating how to define measurement and structural models. The tutorial discusses:
    1. LCA models with response variables;
    2. LCA models with covariates;
    3. 1-step, 2-step and 3-step estimation;
    4. Corrections and other options for 3-step estimation.
  3. Model Selection : a short tutorial discussing:
    1. Selecting the number of latent classes (n_components);
    2. Comparing models with AIC and BIC.

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

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-0.3.0.tar.gz (44.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stepmix-0.3.0-py3-none-any.whl (35.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for stepmix-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b9d409cd2f900072d2d6d98d453530919053f97a3adae677d5ebcacb17fe2d61
MD5 1228b71d36ca2ae2b0216fe9f4bab4f3
BLAKE2b-256 2ec3a8ee30c497a7be31e94d48153a10b9cdda74520d860a84515f0d81af8a7f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for stepmix-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b5ddf32f0718ce0024d305b45077b517baa16e51bbbf9c5e0b23955f6ee2e1c
MD5 438c19b2b37c095d65da005101119c8c
BLAKE2b-256 c784c31486fc69fe5a04fb769c095096498ee2f5dc42cb0d2a2e007ab03fd6d9

See more details on using hashes here.

Supported by

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