Skip to content

Commit 0a0224a

Browse files
author
Hugo Bowne-Anderson
authored
Add descr to NB2 section 4
1 parent 1cf7f85 commit 0a0224a

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

notebooks/2.Parameter_estimation_hypothesis_testing.ipynb

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,19 @@
495495
"n_successes_b = np.sum(np.random.uniform(size=N) <= p_b)"
496496
]
497497
},
498+
{
499+
"cell_type": "markdown",
500+
"metadata": {},
501+
"source": [
502+
"Once again, we need to specify our models for $p_a$ and $p_b$. Each will be the same as the CTR example above\n",
503+
"- Binomial likelihoods\n",
504+
"- uniform priors on $p_a$ and $_p$.\n",
505+
"\n",
506+
"We also want to calculate the posterior of the difference $p_a-p_b$ and we do so using `pm.Deterministic()`, which specifies a deterministic random variable, i.e., one that is completely determined by the values it references, in the case $p_a$ & $p_b$.\n",
507+
"\n",
508+
"We'll now build the model:"
509+
]
510+
},
498511
{
499512
"cell_type": "code",
500513
"execution_count": null,
@@ -511,6 +524,13 @@
511524
" diff_clicks = pm.Deterministic('diff_clicks', prob_a-prob_b)"
512525
]
513526
},
527+
{
528+
"cell_type": "markdown",
529+
"metadata": {},
530+
"source": [
531+
"Sample from the posterior and plot them:"
532+
]
533+
},
514534
{
515535
"cell_type": "code",
516536
"execution_count": null,
@@ -533,7 +553,15 @@
533553
"cell_type": "markdown",
534554
"metadata": {},
535555
"source": [
536-
"**Task**: Determine whether the mean beak length of the Galapogas finches differs between species."
556+
"**Task**: Determine whether the mean beak length of the Galapogas finches differs between species. For the mean of each species, use the same model as in previous hand-on section:\n",
557+
"\n",
558+
"- Gaussian likelihood;\n",
559+
"- Normal prior for the means;\n",
560+
"- Uniform prior for the variances.\n",
561+
"\n",
562+
"Also calculate the difference between the means and, for bonus points, the _effect size_, which is the difference between the means divided by the pooled standard deviations = $\\sqrt{(\\sigma_1^2+\\sigma_2^2)/2}$. Hugo will talk through the importance of the _effect size_.\n",
563+
"\n",
564+
"Don't forget to sample from the posteriors and plot them!"
537565
]
538566
},
539567
{
@@ -545,9 +573,9 @@
545573
"with pm.Model() as model:\n",
546574
" # Priors for means and variances\n",
547575
" μ_1 = pm.Normal('μ_1', mu=10, sd=5)\n",
548-
" σ_1 = pm.Lognormal('σ_1', 0, 10)\n",
576+
" σ_1 = pm.Uniform('σ_1', 0, 10)\n",
549577
" μ_2 = pm.Normal('μ_2', mu=10, sd=5)\n",
550-
" σ_2 = pm.Lognormal('σ_2', 0, 10)\n",
578+
" σ_2 = pm.Uniform('σ_2', 0, 10)\n",
551579
" # Gaussian Likelihoods\n",
552580
" y_1 = pm.Normal('y_1', mu=μ_1, sd=σ_1, observed=df_fortis['blength'])\n",
553581
" y_2 = pm.Normal('y_2', mu=μ_2, sd=σ_2, observed=df_scandens['blength'])\n",

0 commit comments

Comments
 (0)