Skip to main content

Multichoice Logit Estimation: A library for discrete choice models with single and paired alternatives

Project description

Multe: Multichoice Logit Estimation

Python Version License: MIT Tests

A Python library for estimating discrete choice models where agents can select either single alternatives or unordered pairs of alternatives.

This implements the model as described in Ophem, H.V., Stam, P. and Praag, B.V., 1999. Multichoice Logit: Modeling Incomplete Preference Rankings of Classical Concerts. Journal of Business & Economic Statistics, 17(1), pp.117-128.

Installation

Install from PyPI (once published):

pip install multe

Or install from source for development:

git clone https://github.com/tmonk/multe.git
cd multe
pip install -e .

Quick Start

from multe import MultichoiceLogit, simulate_data

# Generate synthetic data
X, y_single, y_dual, true_beta = simulate_data(N=1000, J=4, K=3, seed=42)

# Fit model
model = MultichoiceLogit(num_alternatives=4, num_covariates=3)
model.fit(X, y_single, y_dual)

# Access fitted coefficients
print(model.coef_)  # Shape: (J-1, K) = (3, 3)

See examples/simple_fit_example.py for a complete example, or examples/basic_example.py for advanced usage.

Model

Agents choose from J alternatives. The utility for agent i and alternative j is:

U_ij = V_ij + epsilon_ij
V_ij = X_i * beta_j
epsilon_ij ~ Gumbel(0, 1)

Each agent makes either:

  • Single choice: Select the alternative with maximum utility
  • Dual choice: Select the top two alternatives as an unordered pair

The mixing probability between single and dual choices is determined by the parameter mix_ratio in simulation.

Probabilities

Single choice (multinomial logit):

P(choose j) = exp(V_ij) / sum_k exp(V_ik)

Dual choice (inclusion-exclusion principle):

P(choose {s,t}) = P(U_s > max_k≠s U_k ∪ U_t > max_k≠t U_k)

Identification

The model fixes beta_0 = 0 for identification, so it estimates (J-1) × K parameters.

Data Format

  • X: Covariates (N, K)
  • y_single: Binary matrix (N, J) where y_single[i,j]=1 if agent i chose alternative j
  • y_dual: Binary tensor (N, J, J) where y_dual[i,s,t]=1 if agent i chose pair {s,t} with s<t

Each agent must have exactly one choice (one entry in either y_single or y_dual).

Performance

Fully vectorized implementation for fast estimation and simulation:

Estimation:

  • ~10ms per 1000 observations (optimization)
  • Example: N=10,000, J=5, K=4 completes in ~0.1s

Recommended optimizer: L-BFGS-B

Run benchmarks: python examples/benchmark.py

API Reference

MultichoiceLogit(num_alternatives, num_covariates)

Model class with methods:

  • fit(X, y_single, y_dual, method='L-BFGS-B') - Fit model using MLE (recommended)
    • Returns self with fitted coef_ attribute
    • Stores optimization details in optimization_result_
  • neg_log_likelihood(flat_beta, X, y_single, y_dual) - Negative log-likelihood
  • gradient(flat_beta, X, y_single, y_dual) - Analytical gradient
  • compute_standard_errors(flat_beta, X, y_single, y_dual) - Standard errors

simulate_data(N, J, K, true_beta=None, mix_ratio=0.5, seed=42)

Generate synthetic data following the RUM framework.

Returns: X, y_single, y_dual, true_beta

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

multe-2.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

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

multe-2-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file multe-2.tar.gz.

File metadata

  • Download URL: multe-2.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for multe-2.tar.gz
Algorithm Hash digest
SHA256 5e321bdc7fae7d22ec779fc526c7aa13523da40e32fb31de9a408383208b5301
MD5 5124c012b6d67383ef55d37c248b7ed4
BLAKE2b-256 71dfb0f49a0b0d8967b80dfac5e3c083f65d491716f7d747cb78ae662b46be33

See more details on using hashes here.

File details

Details for the file multe-2-py3-none-any.whl.

File metadata

  • Download URL: multe-2-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for multe-2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a63a354cd5e93098f70e9d713cef5b77ed3e277fb2e7f2065e0ae2fb0912282
MD5 d11a85c77ea97a4086866299c0aec8b7
BLAKE2b-256 0fb658cac5ce079f049d250fe78b741cd738f17390e96ab9ffea754356e6e2e8

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