Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: fitted MNL choice probabilities only available with sampling of alternatives #69

Open
smmaurer opened this issue Feb 5, 2021 · 0 comments
Assignees

Comments

@smmaurer
Copy link
Member

smmaurer commented Feb 5, 2021

It looks like the MultinomialLogitResults class can only provide fitted probabilities for MergedChoiceTables that are generated with sampling of alternatives. This is a bug; there's no reason we can't calculate probabilities for tables that include all the alternatives. Thanks to @msoltadeo for reporting this.

Diagnosis

What's happening is that mergedchoicetable.py#L316 uses the sample size as a count of the number of alternatives, raising an error if the sample size is None. This should be easy to fix.

Workaround

As a temporary workaround, you can edit the table's sample size property after generating it:

results = choicemodels.MultinomialLogit(...).fit()
mct = choicemodels.MergedChoiceTable(..., sample_size=None)
mct.sample_size = numalts
results.predict(mct)

Or you can do it like this, although the table generation may be substantially slower:

results = choicemodels.MultinomialLogit(...).fit()
mct = choicemodels.MergedChoiceTable(..., sample_size=numalts, replace=False)
results.predict(mct)
@smmaurer smmaurer self-assigned this Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant