2025-03-16

Bayesian Inference

Introduction

  • 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:

    • \(P(\theta | D)\) = Posterior probability (updated belief)
    • \(P(D | \theta)\) = Likelihood (how likely the data is given the hypothesis)
    • \(P(\theta)\) = Prior probability (initial belief)
    • \(P(D)\) = Evidence (total probability of the data)

Breaking Down the Formula (Layman’s Explanation)

  • Prior (\(P(\theta)\)): What you originally believed before seeing new data.
  • Likelihood (\(P(D | \theta)\)): How well the new data fits each possible hypothesis.
  • Evidence (\(P(D)\)): The total probability of observing the data, considering all possibilities.
  • Posterior (\(P(\theta | D)\)): The updated belief after seeing the data.

Example:

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.

Everyday Example

  • Weather Prediction:
    • Suppose the prior probability of rain is 30%.
    • If we see dark clouds (new evidence), we update our belief, increasing the probability of rain.
  • Medical Diagnosis:
    • If a patient has flu-like symptoms, the probability of having the flu increases after considering test results.

Bayes’ Theorem in Action

  • 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)} \]

Understanding prior and posterior

Explanation

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.

Beta distributions analysis

Explanation

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.

3D plot for understanding bayesian approach - code

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")))

3D plot for understanding bayesian approach - graph

Explanation

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.

Conclusion

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!