gbosquechacon / statrethink_course_in_pymc3

Statistical Rethinking course in pymc3
143 stars 44 forks source link

Proposed solution for problem in notebook with linear model of Exercise 2 Week 2 #3

Open sebromano opened 4 years ago

sebromano commented 4 years ago

Hi Gabriel, first of all, let me thank you for your work, it is of great help! I am learning python, pymc3, and bayesian statistics all at once, so having your code is of great help.

I think I figured out why the simple linear regression of Exercise 2 in Week 2 does not work in your notebook, when working with log(weights) to predict (while it works in the results for R). It seems that when taking the log of weights, you should also transform the prior for beta, in the linear regression of model_2: mu = alpha + beta * log_weight

so that beta's prior now should be: beta = pm.Lognormal('beta', mu=0, sd=1)

instead of the previos prior of model_1: beta = pm.Normal('beta', mu=0, sd=1) used when working with weights as a predictor.

When using the lognormal prior, the linear model works similarly to the results obtained with the R code. It seems that the normal prior for beta is a bad one, preventing the model from proper fitting. Hope it helps! Sebastian.

gbosquechacon commented 4 years ago

Oh good catch! Thanks for reporting it. I'll try to update the notebook this weekend : )