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.4.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.4-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mlogitviz-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 56be08f818da3008a5cd692ace21bd8519ef762769b5dec7215f95b4a68a59a2
MD5 c8dac7b3cb3a53dbe25803b085d270b7
BLAKE2b-256 7ab79b83d780e8a8e1719805bc8bb6be221e826d305f6ee5054b887c3dcfc9e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mlogitviz-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f21daf7e2a85bfb09c0a1185fbece3405ee487c7a68a3627436d268fbd86e3fb
MD5 075196c7d7cc5f301acbf6e41b13a38f
BLAKE2b-256 2ac50bb26297c2e265784b2285a007bae4d7463fd548d86d78d961c235c9d251

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