Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added 3.10.7
  • Loading branch information
jeremyteitelbaum committed Apr 12, 2018
1 parent eafa025 commit 8b47394
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 8 deletions.
11 changes: 3 additions & 8 deletions BDA 3.10.4.ipynb
Expand Up @@ -31,14 +31,10 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"#(a). Since p0 and p1 are binomially distributed and independent,\n",
"# the noninformative prior is the beta(1,1) distribution and the posterior \n",
"# distributions are p0~beta(636,40) and p1~(659,23)."
"# Here we use the beta(1,1) uniform prior"
]
},
{
Expand Down Expand Up @@ -81,7 +77,6 @@
"ax[2].hist(odds_ratio,bins=50)\n",
"o=ax[2].set_title('Odds Ratios')\n",
"plt.show()\n",
"\n",
"print('odds summary:',np.mean(odds_ratio),np.var(odds_ratio),np.percentile(odds_ratio,[.025,25,50,75,97.5]))\n",
"\n"
]
Expand All @@ -90,7 +85,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Here we use the beta(0,0) improper prior; the effect is pretty minimal"
"# Here we use the beta(0,0) improper prior; the difference from the previous case is small"
]
},
{
Expand Down
71 changes: 71 additions & 0 deletions BDA 3.10.7.ipynb
@@ -0,0 +1,71 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Problem 3.10.7\n",
"\n",
"Poisson and binomial distributions: a student sits on a street corner for an hour and records the number of bicycles $ b $ and the number of other vehicles $v$ that go by. Two models are considered: \n",
"\n",
"* The outcomes $b$ and $v$ have independent Poisson distributions, with unknown means $\\theta_b$ and $\\theta_v$ . \n",
"\n",
"* The outcome $b$ has a binomial distribution, with unknown probability $p$ and sample size $b + v$. \n",
"\n",
"Show that the two models have the same likelihood if we define $p = \\theta_b/( \\theta_b +\\theta_v)$.\n",
"\n",
"Gelman, Andrew; Carlin, John B.; Stern, Hal S.; Dunson, David B.; Vehtari, Aki; Rubin, Donald B.. Bayesian Data Analysis, Third Edition (Chapman & Hall/CRC Texts in Statistical Science) (Page 81). CRC Press. Kindle Edition. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This problem has no computational element, it's a fact about poisson distributions. In the first case we have\n",
"$$\n",
"P(b=b_0)=\\frac{\\theta_b^{b_0}e^{-\\theta_b)}}{b_0!}\n",
"$$\n",
"and\n",
"$$\n",
"P(v=v_0)=\\frac{\\theta_v^{v_0}e^{-\\theta_v)}}{v_0!}\n",
"$$\n",
"It's also a fact that the sum of two poisson variables with rates $\\theta_v$ and $\\theta_b$ is poisson with \n",
"rate $\\theta_v+\\theta_b$. \n",
"\n",
"A direct calculation gives \n",
"$$\n",
"P(b=b_0,v=v_0|b_0+v_0=N)=\\binom{N}{b_0}\\frac{\\theta_b^{b_0}\\theta_v^{N-b_0}}{(\\theta_b+\\theta_v)^{N}}\n",
"$$\n",
"which is what we're supposed to show."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 8b47394

Please sign in to comment.