Skip to main content

A library to compute and visualize marginal effects for multinomial logistic regression models

Project description

mlogitviz

mlogitviz is a Python package designed to visualize changes in predicted probabilities from multinomial logistic regression models. It simplifies interpreting complex models, especially those involving Likert-scale predictors or other categorical data.

Installation

To install mlogitviz, run:

pip install mlogitviz

Usage

import pandas as pd
from mlogitviz import visualize_mlogit

# Load your dataset
df = pd.read_csv("your_data.csv")

# Define key parameters
dependent_var = "outcome"  # Your categorical dependent variable
independent_vars = ["predictor1", "predictor2", "predictor3"]  # Independent variables
baseline_category = "Baseline_Outcome"

# Visualize with custom parameters
visualize_mlogit(df, dependent_var, independent_vars,
                  baseline=baseline_category,
                  significance=0.05,
                  margeff_at='overall',
                  margeff_count=False,
                  output_file="heatmap.png")

Parameters

  • df (pd.DataFrame): Data containing the dependent and independent variables.
  • dependent (str): The name of the dependent variable (categorical).
  • independent (list of str): List of predictor variables (continuous or categorical).
  • baseline (str): Reference category for interpreting marginal effects.
  • significance (float, default=0.05): Threshold for displaying statistically significant effects.
  • margeff_at (str, default='overall'): Controls how marginal effects are computed.
    • 'overall': Recommended for Likert scales or diverse data types.
    • 'mean': Uses the mean values of predictors for marginal effects.
  • margeff_count (bool, default=False): Treats count variables as continuous (False) or calculates changes when increased by one unit (True).
  • output_file (str or None): Path to save the visualization as an image file. If None, it will be displayed directly.

Example Output

  • The heatmap visualizes changes in probabilities, showing:
    • Positive values (red) = increased likelihood.
    • Negative values (blue) = decreased likelihood.
    • Baseline effects appear as a separate column with no significance indicators.

Credits

This package was co-authored by Payam Saeedi and Eric Williams.

License

This project is licensed under the MIT License.

Citing this Package

If you use mlogitviz in your research, please cite:

Payam Saeedi and Eric Williams. mlogitviz: Visualizing Marginal Effects in Multinomial Logistic Regression. Version 0.1.4. URL: https://pypi.org/project/mlogitviz/

BibTeX

@software{mlogitviz,
  author = {Payam Saeedi and Eric Williams},
  title = {mlogitviz: Visualizing Marginal Effects in Multinomial Logistic Regression},
  year = {2024},
  version = {0.1.4},
  url = {https://pypi.org/project/mlogitviz/}
}

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

mlogitviz-0.1.5.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

mlogitviz-0.1.5-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file mlogitviz-0.1.5.tar.gz.

File metadata

  • Download URL: mlogitviz-0.1.5.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for mlogitviz-0.1.5.tar.gz
Algorithm Hash digest
SHA256 bdbbccf336fa778e040f50c45964e3eee1186aeb3a0f6b0a6a97ee4180506b96
MD5 bbca16a825ff6e6cbd139b8c32622224
BLAKE2b-256 f284eb5c80a2aa409ebba0e7c16f7203628172454551e04f0005c4dce4752cbf

See more details on using hashes here.

File details

Details for the file mlogitviz-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: mlogitviz-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for mlogitviz-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 70e626bc596ea97539d50012026201cdebd150267b3f0b30624df5b546b0fd8c
MD5 89009386867a69e9458bdd7b3d2dd752
BLAKE2b-256 2bf136e5a55c32adbcd6fefef038ba3f9df5946fda7c4c65a05f5905471246ba

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