Skip to content

glm bambi usage (WIP) #177

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 5 commits into from
Jun 16, 2021
Merged

glm bambi usage (WIP) #177

merged 5 commits into from
Jun 16, 2021

Conversation

mjhajharia
Copy link
Member

@mjhajharia mjhajharia commented Jun 10, 2021

addresses issue #91

  • use bambi instead of glm module
  • change imports and other possible bad practices, ensure notebook isnt broken and practices like inference_data=true are followed

Note: I've just started hopefully, i'll finish it in a day or two

cc: @OriolAbril

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@canyon289
Copy link
Member

Skimmed this over and it looks great to me. Will do a more in depth review as well

@review-notebook-app
Copy link

review-notebook-app bot commented Jun 12, 2021

View / edit / reply to this conversation on ReviewNB

canyon289 commented on 2021-06-12T03:58:05Z
----------------------------------------------------------------

This is a nitpick. I think this notebook would benefit from the model graphs that pymc3 can generate using the psuedo code below.

But before you add it lets see if anyone else agrees, otherwise feel free to ignore this

pooled_sales_diagram = pm.model_to_graphviz(model.the_pymc_model_i_forgot_how_to_get_it)


tomicapretto commented on 2021-06-12T12:36:50Z
----------------------------------------------------------------

You can do model.graph() ;)

It calls pm.model_to_graphviz under the hood

OriolAbril commented on 2021-06-12T13:45:47Z
----------------------------------------------------------------

also note the plot is now plotting x and y instead of x_out and y_out which are the real observations

Copy link

You can do model.graph() ;)

It calls pm.model_to_graphviz under the hood


View entire conversation on ReviewNB

Copy link
Member

also note the plot is now plotting x and y instead of x_out and y_out which are the real observations


View entire conversation on ReviewNB

@review-notebook-app
Copy link

review-notebook-app bot commented Jun 12, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-12T13:59:24Z
----------------------------------------------------------------

here bambi is used for the irst time and therefore introduced to readers we have to assume. There should be a markdown cell right before with a couple sentencess and a link to bambi


tomicapretto commented on 2021-06-14T00:19:56Z
----------------------------------------------------------------

Agree on this. Something inspired on our overview here https://github.com/bambinos/bambi and one sentence saying it uses a formula for the model is enough I think.

tomicapretto commented on 2021-06-14T00:21:50Z
----------------------------------------------------------------

I would also mention priors are automatically selected when the user does not specify them. Something in the same spirit than the block that used to start with "Since there are a couple of general linear models that are being"

@review-notebook-app
Copy link

review-notebook-app bot commented Jun 12, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-12T13:59:25Z
----------------------------------------------------------------

the dict called data should not be recomputed, it was intended to show how with the same data but adding 3 outliers we have to change the model


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 12, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-12T13:59:25Z
----------------------------------------------------------------

much of this explanation is no longer relevant


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 12, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-12T13:59:26Z
----------------------------------------------------------------

this needs to be updated to work on windows: https://github.com/pymc-devs/pymc3/wiki/PyMC3-Jupyter-Notebook-Style-Guide


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 12, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-12T13:59:26Z
----------------------------------------------------------------

this needs a link to bambi or formulae to explain syntax of group effects


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 12, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-12T13:59:27Z
----------------------------------------------------------------

might want to set marginals=True


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 12, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-12T13:59:28Z
----------------------------------------------------------------

reading the dta here should follow https://github.com/pymc-devs/pymc3/wiki/PyMC3-Jupyter-Notebook-Style-Guide


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 12, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-12T13:59:28Z
----------------------------------------------------------------

I would add a cell with plot posterior using ref_vals to keep the P(weight < 0) = 0.1845

P(height < 0) = 0.0 info in a graphical way


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 12, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-12T13:59:29Z
----------------------------------------------------------------

what is male alpha? do we want to show i in the plot_pair? why wasn' in the old model?


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 12, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-12T13:59:29Z
----------------------------------------------------------------

is statsmodels still used?


almostmeenal commented on 2021-06-15T14:57:07Z
----------------------------------------------------------------

nope, i'll remove it. also since we're using the graphviz figure i'll import that so its a known dependency

@OriolAbril
Copy link
Member

Added several comments, this is great work

@review-notebook-app
Copy link

review-notebook-app bot commented Jun 13, 2021

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2021-06-13T08:22:46Z
----------------------------------------------------------------

Line #2.    plt.plot(x, y, "x")

This should plot the outlier data.


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 13, 2021

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2021-06-13T08:22:47Z
----------------------------------------------------------------

Pretty obvious funnel, here you could link to https://twiecki.io/blog/2017/02/08/bayesian-hierchical-non-centered/


Copy link

Agree on this. Something inspired on our overview here https://github.com/bambinos/bambi and one sentence saying it uses a formula for the model is enough I think.


View entire conversation on ReviewNB

Copy link

I would also mention priors are automatically selected when the user does not specify them. Something in the same spirit than the block that used to start with "Since there are a couple of general linear models that are being"


View entire conversation on ReviewNB

@review-notebook-app
Copy link

review-notebook-app bot commented Jun 14, 2021

View / edit / reply to this conversation on ReviewNB

tomicapretto commented on 2021-06-14T00:27:14Z
----------------------------------------------------------------

This is about the old behavior with PyMC3. I could help with some similar words but in a Bambi context, just let me know :)


Copy link
Member Author

nope, i'll remove it. also since we're using the graphviz figure i'll import that so its a known dependency


View entire conversation on ReviewNB

@mjhajharia
Copy link
Member Author

Added several comments, this is great work

thankyou @OriolAbril !!!

@canyon289
Copy link
Member

I think this is great shape now. Can we mark it ready for merge?

@mjhajharia
Copy link
Member Author

mjhajharia commented Jun 16, 2021

I think this is great shape now. Can we mark it ready for merge?

sure thing! you can do it, or else I'm on my phone rn i'll do it in afternoon, also thanks for the graphviz comment that looks cool and useful :))

@twiecki twiecki marked this pull request as ready for review June 16, 2021 07:04
@twiecki twiecki merged commit b579d1e into pymc-devs:main Jun 16, 2021
@twiecki
Copy link
Member

twiecki commented Jun 16, 2021

Thanks @almostmeenal!

@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-16T08:54:28Z
----------------------------------------------------------------

This will be the first contact with bambi for probably hundreds of people a month. I think this needs a link to bambi documentation more than a link to its paper. Having both is probably fine too, but I think this paper linked here is outdated. cc @tomicapretto @canyon289

Extra side note that unlike the above should not be implemented until after 3.11.3 when we start using myst. We could have a link to the documentation plus a clickable [1] that goes to the bottom of the notebook where references are with the bambi paper.


aloctavodia commented on 2021-06-16T09:00:52Z
----------------------------------------------------------------

Right the correct link to the paper is https://arxiv.org/abs/2012.10754 and the documentation is here https://bambinos.github.io/bambi/master/index.html

@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-16T08:54:29Z
----------------------------------------------------------------

The explanation is great and the link to the family object too. I also have a myst related extra note here (again, so not implement yet) that we could use intersphinx for that link so that if bambi decides to rename master to main, we'll only have to change a link in conf.py and regenerate docs for everything to work again, otherwise we'll have to track down all links and update them. Same thing if documentation is reorganized, files renamed or moved to a different folder structure


almostmeenal commented on 2021-06-18T10:28:12Z
----------------------------------------------------------------

keeping this comment unresolved for later

@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-16T08:54:30Z
----------------------------------------------------------------

I think people won't know what common is, a note about how this will be clarified below should be enough


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

OriolAbril commented on 2021-06-16T08:54:31Z
----------------------------------------------------------------

A link to a line in the source code on github doesn't feel right for the general introductory level of the content. It could link to https://bambinos.github.io/bambi/master/notebooks/getting_started.html#Specifying-priors or https://bambinos.github.io/bambi/master/api_reference.html#bambi.models.Model.set_priors


Copy link
Member

Right the correct link to the paper is https://arxiv.org/abs/2012.10754 and the documentation is here https://bambinos.github.io/bambi/master/index.html


View entire conversation on ReviewNB

@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

aloctavodia commented on 2021-06-16T09:38:45Z
----------------------------------------------------------------

I think import graphviz is not needed


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

aloctavodia commented on 2021-06-16T09:38:46Z
----------------------------------------------------------------

it should be Bambi


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

aloctavodia commented on 2021-06-16T09:38:47Z
----------------------------------------------------------------

We can avoid doing fitted = results, by directly doing fitted = model.fit(draws=1000)


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

aloctavodia commented on 2021-06-16T09:38:47Z
----------------------------------------------------------------

data_outlier already is a data frame so we can domodel = bambi.Model("y ~ x", data_outlier)


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

aloctavodia commented on 2021-06-16T09:38:48Z
----------------------------------------------------------------

Bambi/PyMC3


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

aloctavodia commented on 2021-06-16T09:38:49Z
----------------------------------------------------------------

unify:

normal/Normal

student T/student-t (also later in the example we have student t)


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

aloctavodia commented on 2021-06-16T09:38:49Z
----------------------------------------------------------------

Maybe we should used a different prior than a Uniform distribution, like a HalfNormal


@review-notebook-app
Copy link

review-notebook-app bot commented Jun 16, 2021

View / edit / reply to this conversation on ReviewNB

aloctavodia commented on 2021-06-16T09:38:50Z
----------------------------------------------------------------

You can remove the plt.show() from this and the other cells


Copy link
Member Author

keeping this comment unresolved for later


View entire conversation on ReviewNB

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.

6 participants