Skip to main content

A Python package for multi-step 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

Build Status Documentation Status Code style: black

This project is currently in development and a stable release is expected sometime during summer 2022.

A Python package for multi-step 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. Largely based on Bakk & Kuha, 2018.

Install

You can install this repo directly with pip, preferably in a virtual environment :

pip install --upgrade git+https://github.com/Labo-Lacourse/stepmix.git

Usage

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=.7, 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.0.3.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

stepmix-0.0.3-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for stepmix-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ac382a8068e4fc5f8f0d0a79e4b8abeea2a644795494bab2dcee5f76bdc9cf99
MD5 bb1948906821108e59c295e6bdc25e2f
BLAKE2b-256 2d06a7ab8d4e5de1b9b26fe10109ed93c610fec0d1dae80a7e168328a5cc1873

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for stepmix-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1a1b5d6818e639948e2acd61935867b196dfd8c7ba5dfabe4ec92034acd73b45
MD5 61eaa12d4ec0718a76802eb0ec050e8a
BLAKE2b-256 6034ba213de42b8c8203d1feb744b1424275c756c4cbabd38ce25a182bf110f9

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