Simulating posterior draws
You have just decided to use a Beta(5, 2) prior for the efficacy rate. You are also using the binomial distribution to model the data (curing a sick patient is a "success", remember?). Since the beta distribution is a conjugate prior for the binomial likelihood, you can simply simulate the posterior!
You know that if the prior is \(Beta(a, b)\), then the posterior is \(Beta(x, y)\), with:
\(x = NumberOfSuccesses + a\),
\(y = NumberOfObservations - NumberOfSuccesses + b\).
Can you simulate the posterior distribution? Recall that altogether you have data on 22 patients, 19 of whom have been cured. numpy and seaborn have been imported for you as np and sns, respectively.
Este ejercicio forma parte del curso
Bayesian Data Analysis in Python
Instrucciones del ejercicio
- Assign the numbers of patients treated and cured to
num_patients_treatedandnum_patients_cured, respectively. - Use the appropriate
numpyfunction to sample from the posterior distribution and assign the result toposterior_draws. - Plot the posterior distribution using the appropriate
seabornfunction.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Define the number of patients treated and cured
num_patients_treated = ____
num_patients_cured = ____
# Simulate 10000 draws from the posterior distribuition
posterior_draws = ____(____ + ____, ____ - ____ + ____, 10000)
# Plot the posterior distribution
____(____, shade=True)
plt.show()