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 exercício faz parte do curso
Bayesian Data Analysis in Python
Instruções do exercício
- 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.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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()