Skip to content

convenience function to help compare models using WAIC or LOO #1775

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

Merged
merged 6 commits into from
Feb 15, 2017

Conversation

aloctavodia
Copy link
Member

This is a simple function that computes WAIC or LOO (IC) for a set of models and return a DataFrame ordered from "best" to "worse" model (in terms of the IC). It also computes other quantities like Akaike weights that can be used for example for model averaging and the standard error of the difference in IC between each model and the top-ranked model, that can help to compare and interpret IC for different models. A similar function is used extensively in the book Statistical Rethinking by Richard McElreath.

In a future PR I will add a plot based on this function (I guess it should be a separate function living inside plots). And I will update the notebook examples to give some details on this function and how it can helps to interpret IC (beyond the "smaller is better" rule ).

One current problem with this function is that the warnings returned by waic/loo are not very useful given that the user does not know which model is returning a warning or even if there is more than one warning.

I am not sure which is the best solution here. A couple of alternatives are:

  1. To catch the warning and print it together with the model index.
  2. To add a "warning" column in the output DataFrame (filled with boolean maybe). These values could be obtained by catching the warning inside compare, or by modifying waic/loo to return such a value.

I think the second option (including the modification of waic/loo) is a better option. What do you think?

@twiecki
Copy link
Member

twiecki commented Feb 13, 2017

@aloctavodia Catching the warnings would be the pythonic way I think.

pymc3/stats.py Outdated
@@ -281,10 +281,10 @@ def compare(traces, models, ic='WAIC'):
Returns
-------
A DataFrame, ordered from lowest to highest IC. The index reflects
the order in which the models are passed to this function. The columns are:
the order in wich the models are passed to this function. The columns are:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

pymc3/stats.py Outdated
Smaller IC indicates higher out-of-sample predictive fit ("better" model).
Default WAIC.
Smaller IC indicates higher out-of-sample predictive fit ("better" model).
Default WAIC.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stray spaces

@twiecki
Copy link
Member

twiecki commented Feb 14, 2017

An example would also be good.

pymc3/stats.py Outdated

Parameters
----------
traces: list of PyMC3 traces
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

varname : description

@twiecki twiecki merged commit af6eaeb into pymc-devs:master Feb 15, 2017
@aloctavodia
Copy link
Member Author

@twiecki thanks for the reviews!

@aloctavodia aloctavodia deleted the compare_waic_loo branch February 15, 2017 22:48
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

Successfully merging this pull request may close these issues.

2 participants