Skip to content

Commit

Permalink
Fixed typos in chapter 13 notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
alex_ndorah authored and rosgori committed Dec 3, 2019
1 parent 6dc2250 commit 37fccc8
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions Rethinking/Chp_13.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"For complicate model it is always good to do more checks:"
"For complex models it is always good to do more checks:"
]
},
{
Expand Down Expand Up @@ -854,10 +854,10 @@
" corr = tt.diag(sigma_ab**-1).dot(cov.dot(tt.diag(sigma_ab**-1)))\n",
" r = pm.Deterministic('Rho', corr[np.triu_indices(2, k=1)])\n",
" \n",
" mu = pm.MvNormal('ab_cafe', mu=tt.stack([a, bm]), chol=chol, shape=(Ndept, 2))\n",
" mu = pm.MvNormal('ab_dept', mu=tt.stack([a, bm]), chol=chol, shape=(Ndept, 2))\n",
" \n",
" a_dept = pm.Deterministic('a_dept', mu[:, 0])\n",
" a_dept = pm.Deterministic('bm_dept', mu[:, 1])\n",
" bm_dept = pm.Deterministic('bm_dept', mu[:, 1])\n",
" \n",
" p = pm.math.invlogit(mu[Dept_id, 0] + mu[Dept_id, 1] * d_ad['male'])\n",
" admit = pm.Binomial('admit', p=p, n=d_ad.applications, observed=d_ad.admit)\n",
Expand Down Expand Up @@ -1491,7 +1491,7 @@
"metadata": {},
"source": [
"#### Code 13.28\n",
"Actually in model m_13_6NC I am already using the Cholesky decomposition of the covariance matrix. If we want to strictly follow the parameterization of m13.6NC and m13.6nc1 as in the book, we will model the Rho using pm.LKJCorr and do multiplication it with pm.HalfCauchy."
"Actually in model m_13_6NC I am already using the Cholesky decomposition of the covariance matrix. If we want to strictly follow the parameterization of m13.6NC and m13.6nc1 as in the book, we will model Rho using pm.LKJCorr and multiply it with pm.HalfCauchy."
]
},
{
Expand Down Expand Up @@ -2096,6 +2096,7 @@
}
],
"source": [
"# Summary of centered model\n",
"pm.summary(trace_13_7, varnames=['g', 'a', 'bp', 'etasq', 'rhosq']).round(2)"
]
},
Expand Down Expand Up @@ -2303,6 +2304,7 @@
}
],
"source": [
"# Summary of non-centered model\n",
"pm.summary(trace_13_7_, varnames=['g', 'a', 'bp', 'etasq', 'rhosq']).round(2)"
]
},
Expand Down Expand Up @@ -2348,7 +2350,7 @@
"\n",
"ax.set_ylim(0, 1)\n",
"ax.set_xlabel('distance')\n",
"ax.set_ylabel('correlation');"
"ax.set_ylabel('covariance');"
]
},
{
Expand Down Expand Up @@ -2656,21 +2658,23 @@
}
],
"source": [
"# compute posterior median relationship, ignoring distance\n",
"Nsamp, Nbin = 1000, 30\n",
"log_pop_seq = np.linspace(6, 14, Nbin)\n",
"a_post = trace_13_7.get_values(varname='a', combine=True)[:, None]\n",
"bp_post = trace_13_7.get_values(varname='bp', combine=True)[:, None]\n",
"lambda_post = np.exp(a_post + bp_post*log_pop_seq)\n",
"\n",
"# plot raw data\n",
"_, axes = plt.subplots(1, 1, figsize=(5, 5))\n",
"axes.plot(log_pop_seq, np.median(lambda_post, axis=0), '--', color='k')\n",
"\n",
"alpha = .2\n",
"\n",
"# display posterior predictions\n",
"axes.plot(log_pop_seq, np.median(lambda_post, axis=0), '--', color='k')\n",
"mu_hpd = pm.hpd(lambda_post, alpha=alpha)\n",
"axes.fill_between(log_pop_seq,\n",
" mu_hpd[:,0], mu_hpd[:,1], alpha=alpha*.5+.1, color='k')\n",
"\n",
"# plot raw data and labels\n",
"axes.scatter(dk['logpop'], dk['total_tools'], psize)\n",
"labels = dk['culture'].values\n",
"for i, itext in enumerate(labels):\n",
Expand Down Expand Up @@ -2726,9 +2730,9 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "stat-rethink-pymc3",
"language": "python",
"name": "python3"
"name": "stat-rethink-pymc3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -2740,7 +2744,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 37fccc8

Please sign in to comment.