Skip to content

Update radon example NB #3765

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 22 commits into from
Jan 10, 2020
Merged

Conversation

AlexAndorra
Copy link
Contributor

Finally got time to finish this PR 🍾
I noticed on Discourse that the radon notebook is often used as an introduction to hierarchical models, but several questions were recurring so I thought it'd useful to:

  • Update with new code and versions of PyMC and ArviZ
  • Replace flat priors by weakly regularizing ones (both to encourage best practices and to preemptively answer Discourse questions)
  • Add prior predictive checks
  • Replace the section about varying-slopes only by a model including the covariance between varying slopes and varying intercepts
  • Implement non-centered versions of the hierarchical models (this is necessary in this case to get rid of divergences + we often get questions about that, so this will hopefully be a useful ressource)
  • Update and add graphs
  • Do some miscellaneous changes

First PR on the main repo (🎉 ), so tell me if I forgot anything. And of course I'm available for any change.
Happy new year & PyMCheers 🖖

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

You'll be able to see Jupyter notebook diff and discuss changes. Powered by ReviewNB.

@codecov
Copy link

codecov bot commented Jan 8, 2020

Codecov Report

Merging #3765 into master will increase coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3765      +/-   ##
==========================================
+ Coverage   90.55%   90.63%   +0.07%     
==========================================
  Files         133      133              
  Lines       20316    20328      +12     
==========================================
+ Hits        18397    18424      +27     
+ Misses       1919     1904      -15
Impacted Files Coverage Δ
pymc3/tests/test_model.py 100% <0%> (ø) ⬆️
pymc3/sampling.py 83.11% <0%> (+0.02%) ⬆️
pymc3/step_methods/compound.py 95.12% <0%> (+0.12%) ⬆️
pymc3/model.py 89.17% <0%> (+1.91%) ⬆️

@fonnesbeck
Copy link
Member

Thanks for doing this! -- its definitely an upgrade.

A couple of notes:

  • for didactic purposes, it might be best to separate sampling and posterior predictive sampling into tow different cells (at least for the first time it is presented)
  • spelling: should be "envelope" (a noun) not "envelop" (a verb)
  • its probably best to use cores=2 rather than chains=2 in calls to sample, as for some systems (e.g. Colab, some Chromebooks) the latter will result in sequential sampling of chains.
  • add plt.tight_layout() call to multi-panel plots to make the labels more readable (at least the ones showing the county-wise estimates)
  • why not use the symbol ρ rather than spelling out "Rho", since we use symbols for the other Greek letters?

@AlexAndorra
Copy link
Contributor Author

Thanks Chris!
I integrated all your points and I just had a small remaining question: I removed chains=2 and didn't specify a number of cores (since I understood that parallel sampling is not possible on Windows), but now the fit is worse for complex models (starting from varying_intercept_slope): some divergences and the acceptance probability does not match the target.
Do you know what could be the cause? (Running on Mac, 4 chains in 4 job)

@AlexAndorra
Copy link
Contributor Author

Ok I think I figured it out: it needed a mix of increased tuning and higher target accept. Pushing the changes ;)

@review-notebook-app
Copy link

review-notebook-app bot commented Jan 8, 2020

View / edit / reply to this conversation on ReviewNB (backstory for this conversation format).

michaelosthege commented on 2020-01-08T18:13:28Z
----------------------------------------------------------------

The warnings thrown by this cell were fixed in a recent arviz PR: https://github.com/arviz-devs/arviz/pull/989/files

If you update your arviz and re-run, they should go away.


AlexAndorra commented on 2020-01-09T10:22:16Z
----------------------------------------------------------------

Thanks for the flag Michael, I updated and re-ran ;)

@review-notebook-app
Copy link

review-notebook-app bot commented Jan 9, 2020

View / edit / reply to this conversation on ReviewNB (backstory for this conversation format).

aloctavodia commented on 2020-01-09T18:21:27Z
----------------------------------------------------------------

There is no longer need to use %matplotlib inline

It is better to set the style az.style.use("arviz-darkgrid") in a cell other than the one used to import arviz, otherwise not all the setting in the arviz (or matploblib) style will be properly set.


AlexAndorra commented on 2020-01-10T09:13:18Z
----------------------------------------------------------------

Ow thanks, didn't know that! Just pushed the changes ;)

@aloctavodia
Copy link
Member

Good to see you around @AlexAndorra, I just added a couple of super minor comments. I really like what you did with this notebook.

@AlexAndorra
Copy link
Contributor Author

Ha ha thx Osvaldo, glad to be around too - the neighborhood is pretty cool 😉

@aloctavodia aloctavodia merged commit edca817 into pymc-devs:master Jan 10, 2020
sthagen added a commit to sthagen/pymc-devs-pymc that referenced this pull request Jan 10, 2020
@AlexAndorra AlexAndorra deleted the update-radon branch May 13, 2020 17:25
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.

3 participants