2025-03-16
Bayesian Inference is a method of statistical inference that updates our beliefs based on new evidence.
It relies on Bayes’ Theorem:
\[ P(\theta | D) = \frac{P(D | \theta) P(\theta)}{P(D)} \]
where:
Imagine you’re guessing whether a friend is lying.
- Prior: You think they lie 10% of the time.
- Likelihood: You notice they cough (which happens 80% of the time when they lie).
- Evidence: But they also cough 30% of the time even when telling the truth.
- Posterior: Using Bayes’ Theorem, you update your belief that they might be lying.
Suppose a COVID-19 test is 95% accurate.
If 1% of the population has COVID-19, what is the probability that someone who tests positive actually has COVID-19?
\[ P(COVID | Positive) = \frac{P(Positive | COVID) P(COVID)}{P(Positive)} \]
The blue dashed line represents our prior belief before seeing new data. The red line shows how our belief has been updated after seeing evidence. Example: If you originally thought it would rain (prior), but then saw dark clouds (evidence), your belief in rain (posterior) increases.
Probabilities that vary over time can be modeled using beta distributions. A perception that something is equally likely is known as the “green curve.” Purple Curve: The idea that experience increases the likelihood of success. Example: You may assume that you have a 50% chance of parking successfully when you are a rookie driver, but after practice, you come to believe that it is 80% likely.
library(plotly) # installing plotly
# Generate a 3D Bayesian updating surface
theta <- seq(0, 1, length.out=30)
# The function dbeta(x, alpha, beta) gives the density of the Beta distribution
# We use outer() to apply this function over a grid of (x, y) values
likelihood <- outer(theta, theta, function(x, y) dbeta(x, 5, 5) * dbeta(y, 2, 5))
# so we do prob before vs prob after vs likelihood
plot_ly(x = theta, y = theta, z = likelihood, type = "surface") %>%
layout(title = "3D Bayesian Updating",
scene = list(xaxis = list(title = "Prob 1"),
yaxis = list(title = "Prob 2"),
zaxis = list(title = "Likelihood")))
This 3D surface illustrates how our beliefs change as we gather more information. Every update shifts our belief a little bit closer to the most likely scenario. For instance, you might lower your belief if you believe a stock will rise but bad news breaks.
Bayesian inference continuously updates beliefs based on new data. It has applications in science, AI, medicine, and finance. It provides a flexible alternative to traditional statistics.
Thank you!