1. Learn
  2. /
  3. Courses
  4. /
  5. Bayesian Data Analysis in Python

Connected

Exercise

Simulate beta posterior

In the upcoming few exercises, you will be using the simulate_beta_posterior() function you saw defined in the last video. In this exercise, you will get a feel for what the function is doing by carrying out the computations it performs.

You are given a list of ten coin tosses, called tosses, in which 1 stands for heads, 0 for tails, and we define heads as a "success". To simulate the posterior probability of tossing heads, you will use a beta prior. Recall that if the prior is \(Beta(a, b)\), then the posterior is \(Beta(x, y)\), with:

\(x = \text{NumberOfHeads} + a\)

\(y = \text{NumberOfTosses} - \text{NumberOfHeads} + b\)

Instructions 1/2

undefined XP
  • 1
    • Set both prior parameters, beta_prior_a and beta_prior_b, to 1.
    • Calculate the number of heads and assign it to num_successes.
    • Generate posterior draws according to the formula above and assign the result to posterior_draws.
  • 2
    • Set the prior parameters, beta_prior_a and beta_prior_b, to 1 and 10, respectively.
    • Calculate the number of heads and assign it to num_successes.
    • Generate posterior draws according to the formula above and assign the result to posterior_draws.