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

Plot comparisons notebook for docs #695

Merged
merged 84 commits into from
Jul 10, 2023

Conversation

GStechschulte
Copy link
Collaborator

This PR adds a demo notebook for the Bambi docs explaining the following:

  • what the methodology (average predictive comparisons) behind comparisons and plot_comparisons is
  • how to use comparisons and plot_comparisons and the various quantities of interest: unit level, grid, average

Ultimately, this docs example builds off of this blog post, but will go into more detail along with more examples.

This is a draft PR and can only be merged once #684 is merged.

deleted docs/notebooks/plot_cap.ipynb#
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@codecov-commenter
Copy link

codecov-commenter commented Jul 4, 2023

Codecov Report

Merging #695 (6f269e0) into main (0fa0b6f) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #695   +/-   ##
=======================================
  Coverage   87.91%   87.91%           
=======================================
  Files          43       43           
  Lines        3318     3318           
=======================================
  Hits         2917     2917           
  Misses        401      401           
Impacted Files Coverage Δ
bambi/plots/plotting.py 88.77% <ø> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tomicapretto
Copy link
Collaborator

Reads soooo well! Amazing work!!!

@GStechschulte
Copy link
Collaborator Author

Reads soooo well! Amazing work!!!

Thank you! I'm excited to get user feedback and tests.

@GStechschulte GStechschulte marked this pull request as ready for review July 6, 2023 07:45
@tomicapretto
Copy link
Collaborator

tomicapretto commented Jul 6, 2023

Just left a very small comment. It looks so good. If you want, feel free to add a note at the end saying this was authored by you as part of your GSoC project.

I only have two questions (for now)

  • Should the results of comparisons contain the computed operation? diff, ratio, etc.
  • In the "Default contrast and conditional values" it says "Bambi computes the mean and then subtracts and adds 2.5 units..." Does it work the same way in marginaleffects? I'm thinking about how well it can work with different scales of data.

edit I think this is ready to be merged

@@ -0,0 +1,1958 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line #6.    from bambi.plots import comparisons, plot_comparison

We should be able to import bambi once and then call the plots submodel directly, like

import bambi as bmb

bmb.comparisons or bmb.plot_comparison


Reply via ReviewNB

docs/notebooks/plot_comparisons.ipynb Show resolved Hide resolved
@@ -0,0 +1,1958 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is possible to specify 1 to 2 and 1 to 4 comparisons by writing something like contrast={"persons": [1, (2, 4)]} or with some other syntax?


Reply via ReviewNB

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this can be achieved by passing

contrast={"persons": [1, 2, 4]}

and since we use list(itertools.combinations(contrast.values, 2)) where contrast.values = [1, 2, 4], the contrasts end up being a pairwise combination:

(1, 2), (1, 4), (2, 4)

Copy link
Collaborator

Choose a reason for hiding this comment

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

That will generate all combinations, I am asking if it is possible (or even desireable) to write something like this (not necessarily this) contrast={"persons": [1, (2, 4)]} and get [(1,2), (1,4)] .

docs/notebooks/plot_comparisons.ipynb Show resolved Hide resolved
@GStechschulte
Copy link
Collaborator Author

GStechschulte commented Jul 6, 2023

Just left a very small comment. It looks so good. If you want, feel free to add a note at the end saying this was authored by you as part of your GSoC project.
I only have two questions (for now)
  • Should the results of comparisons contain the computed operation? diff, ratio, etc.
  • In the "Default contrast and conditional values" it says "Bambi computes the mean and then subtracts and adds 2.5 units..." Does it work the same way in marginaleffects? I'm thinking about how well it can work with different scales of data.
edit I think this is ready to be merged

Thank you! :)

Should the results of comparisons contain the computed operation? diff, ratio, etc.

Currently it does because: (1) if the user wants the estimates, etc. without plotting then this function offers that possibility, and (2) if the user wants to perform their own plotting (for whatever reason) then they have access to the same data we use for plotting. What are your thoughts?

In the "Default contrast and conditional values" it says "Bambi computes the mean and then subtracts and adds 2.5 units..." Does it work the same way in marginaleffects? I'm thinking about how well it can work with different scales of data.

Very good point. By default, I use a one unit centered difference, i.e., $\pm$ $0.5$. For example, if the user does not pass any value for contrast="persons", then $\pm$ $0.5$ is applied to the mean of persons. I added additional wording to clarify the distinction between default centered differences and centered differences when a user passes their own value.

Copy link
Collaborator

@aloctavodia aloctavodia left a comment

Choose a reason for hiding this comment

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

LGTM

@GStechschulte
Copy link
Collaborator Author

LGTM

Thanks for the review! Much appreciated!

@tomicapretto
Copy link
Collaborator

@GStechschulte now we have some conflicts. I can merge once they are fixed :)

@GStechschulte
Copy link
Collaborator Author

@GStechschulte now we have some conflicts. I can merge once they are fixed :)

Good to go now :) Thanks!

@tomicapretto tomicapretto merged commit 39a06da into bambinos:main Jul 10, 2023
4 checks passed
@GStechschulte GStechschulte deleted the plot-comparisons-docs branch January 21, 2024 20:19
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.

None yet

4 participants