Highest Posterior Density credible intervals
You know that reporting bare point estimates is not enough. It would be great to provide a measure of uncertainty in the drug's efficacy rate estimate, and you have all the means to do so. You decide to add the following to the memo.
The experimental results indicate that with a 90% probability the new drug's efficacy rate is between ___ and ___, and with a 95% probability it is between ___ and ___.
You will need to calculate two credible intervals: one of 90% and another of 95% probability. The drug_efficacy_posterior_draws
array is still available in your workspace.
This is a part of the course
“Bayesian Data Analysis in Python”
Exercise instructions
- Import the
arviz
package asaz
. - Calculate the Highest Posterior Density credible interval of 90% and assign it to
ci_90
. - Calculate the Highest Posterior Density credible interval of 95% and assign it to
ci_95
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import arviz as az
____
# Calculate HPD credible interval of 90%
ci_90 = ____.____(____, ____=____)
# Calculate HPD credible interval of 95%
ci_95 = ____
# Print the memo
print(f"The experimental results indicate that with a 90% probability \nthe new drug's efficacy rate is between {np.round(ci_90[0], 2)} and {np.round(ci_90[1], 2)}, \nand with a 95% probability it is between {np.round(ci_95[0], 2)} and {np.round(ci_95[1], 2)}.")
This exercise is part of the course
Bayesian Data Analysis in Python
Learn all about the advantages of Bayesian data analysis, and apply it to a variety of real-world use cases!
It’s time to look under the Bayesian hood. You’ll learn how to apply Bayes' Theorem to drug-effectiveness data to estimate the parameters of probability distributions using the grid approximation technique, and update these estimates as new data become available. Next, you’ll learn how to incorporate prior knowledge into the model before finally practicing the important skill of reporting results to a non-technical audience.
Exercise 1: Under the Bayesian hoodExercise 2: Towards grid approximationExercise 3: Grid approximation without prior knowledgeExercise 4: Updating posterior beliefExercise 5: Prior beliefExercise 6: The truth of the priorExercise 7: Picking the right priorExercise 8: Simulating posterior drawsExercise 9: Reporting Bayesian resultsExercise 10: Point estimatesExercise 11: Highest Posterior Density credible intervalsExercise 12: The meaning of credibilityWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.