Skip to content

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

@sebromano

Description

@sebromano

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions