aloctavodia / Statistical-Rethinking-with-Python-and-PyMC3

Python/PyMC3 port of the examples in " Statistical Rethinking A Bayesian Course with Examples in R and Stan" by Richard McElreath

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why should both betas have same distribution in quadratic regression?

bluesky314 opened this issue · comments

In 4.66, we set beta to generate two numbers for our quadratic model so both are generated from the same distribution. But the book generates it from two different distributions. Why would we do this? Doesn't this decrease the flexibility of the model?

with pm.Model() as m_4_5:
    alpha = pm.Normal('alpha', mu=178, sd=100)
    
    beta = pm.Normal('beta', mu=0, sd=10, shape=2) # shape of 2 generates two betas
    sigma = pm.Uniform('sigma', lower=0, upper=50)
    mu = pm.Deterministic('mu', alpha + beta[0] * d.weight_std + beta[1] * d.weight_std2)
    height = pm.Normal('height', mu=mu, sd=sigma, observed=d.height)
    trace_4_5 = pm.sample(1000, tune=1000)

By doing beta = pm.Normal('beta', mu=0, sd=10, shape=2) you are sampling from two independent normal distributions each one with mean 0 and standard deviation 10. Thus using shape=2 is a more convenient way of writing

beta1 = pm.Normal('beta1', mu=0, sd=10)
beta2 = pm.Normal('beta2', mu=0, sd=10)

BTW this repository has been deprecated in favor of this one