|
495 | 495 | "n_successes_b = np.sum(np.random.uniform(size=N) <= p_b)" |
496 | 496 | ] |
497 | 497 | }, |
| 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 | + }, |
498 | 511 | { |
499 | 512 | "cell_type": "code", |
500 | 513 | "execution_count": null, |
|
511 | 524 | " diff_clicks = pm.Deterministic('diff_clicks', prob_a-prob_b)" |
512 | 525 | ] |
513 | 526 | }, |
| 527 | + { |
| 528 | + "cell_type": "markdown", |
| 529 | + "metadata": {}, |
| 530 | + "source": [ |
| 531 | + "Sample from the posterior and plot them:" |
| 532 | + ] |
| 533 | + }, |
514 | 534 | { |
515 | 535 | "cell_type": "code", |
516 | 536 | "execution_count": null, |
|
533 | 553 | "cell_type": "markdown", |
534 | 554 | "metadata": {}, |
535 | 555 | "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!" |
537 | 565 | ] |
538 | 566 | }, |
539 | 567 | { |
|
545 | 573 | "with pm.Model() as model:\n", |
546 | 574 | " # Priors for means and variances\n", |
547 | 575 | " μ_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", |
549 | 577 | " μ_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", |
551 | 579 | " # Gaussian Likelihoods\n", |
552 | 580 | " y_1 = pm.Normal('y_1', mu=μ_1, sd=σ_1, observed=df_fortis['blength'])\n", |
553 | 581 | " y_2 = pm.Normal('y_2', mu=μ_2, sd=σ_2, observed=df_scandens['blength'])\n", |
|
0 commit comments