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.

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.3.tar.gz (5.2 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.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mlogitviz-0.1.3.tar.gz
  • Upload date:
  • Size: 5.2 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.3.tar.gz
Algorithm Hash digest
SHA256 70f0e4b2e198bd0b50ab76b5e2b693721acb9da5018f48f0368ce219bc6e964b
MD5 697c2d68311fd454496f3bfa693e17a3
BLAKE2b-256 97057c548736d1753214edc30635140da10f68e5ab586064d7c27a128944c715

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mlogitviz-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b6b4444d68d5b0d2bbb8f6e76779d9db7c7b0a79b7d1c863e1911a6cd967d527
MD5 59efd3eb55fe4a2886ce302bd77d3cd9
BLAKE2b-256 ddfbaf58498ae1565b1ef98342ce4634ab1d8bfd0a079d8757f311f52f384aea

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