Announcing a new project I just completed, a Bayesian probability calculator! This is a personal project I began in 2018 and have recently revisited, improved, and finished up. I took an interest in Bayesian probability (learn about Bayes’ theorem here at statisticshowto.com) some years ago when I recognized how powerful of a tool it is to, basically, help calculate how likely things are to be true (based on the information that you have available). It’s all about taking your prior belief (or the “prior probability” as some value between 0% and 100%) about whether some idea or hypothesis is true, and when you come across some new evidence relating to it, revising the belief by properly factoring in the evidence through considering how expected it was assuming the hypothesis is true and how expected it was assuming the hypothesis isn’t true. It’s not too different from how people might generally take new information into account for informing their beliefs, but Bayes’ theorem frames the question precisely, reminding us to pay attention to false positives and our prior beliefs. So by applying Bayes’ theorem, when we make some new observation, we can consider how expected that observation would be if our prior belief was true and how expected it would be if it wasn’t true, and we can consider that given what we previously thought the chance was for it to be true.
The equation itself looks like P(H|E) = [P(H) × P(E|H)] / [P(H) × P(E|H) + P(¬H) × P(E|¬H)], which means that the probability that a belief is true given new evidence (P(H|E)) can be calculated by multiplying the prior probability for the hypothesis by the expectation for the evidence given the hypothesis (P(H) × P(E|H)), divided by the total expectation for that observation, which is itself the prior probability times the likelihood for the evidence given the hypothesis plus the prior belief that the hypothesis was wrong times the expectation for the evidence given that the hypothesis was wrong (P(H) × P(E|H) + P(¬H) × P(E|¬H)). For a great and intuitive explanation of exactly why this works, I recommend this wonderful video by 3Blue1Brown on YouTube.
To give a simple example of Bayes’ theorem in action, let’s say you’re wondering whether your new friend shares your passion for geology (but you don’t want to, you know, actually ask). “My friend loves geology” may be your hypothesis. And let’s say you initially don’t think it’s very likely to be the case; maybe you think only 20% of people like geology as much as you. So 20% is your prior probability. But then you hear your friend make a geology pun! (“You know, it’s important not to take all igneous rocks for granite!”) Hearing that, you’ll probably automatically think it’s more likely that they do love geology, but how much more likely? In comes the handy Bayesian reasoning, allowing you to take into account the proportion of geology fans who would make a pun like that and the proportion of non-fans who would, in the context of how many people are or aren’t geology fans in the first place. Simply multiply the percent of geology fans (20%) by the percent of geology fans who would make such a pun, which maybe you’ll estimate that at about 80% (since they love their puns!), giving you 16%. Then multiply the percent of non-fans (80%) by the percent of non-fans who would make the pun, which maybe you’ll estimate that at about 10%, giving you 8%. That original 20% vs 80% population split now is whittled down by those who tell puns to become 16% (geology fans) vs 8% (non-fans). With that, you can intuitively recognize now that it’s twice as likely that your friend is a geology fan than that they aren’t. Putting the numbers into the final form of the equation, you can see that the probability is 0.16/(0.16+0.8), which, based on those assumptions, equals a 66.7% chance that your friend loves geology as much as you do.
Bayes’ theorem can be useful when intuitively applied, but I wanted to make a tool that would allow me to quickly and easily calculate exact probabilities. After all, plugging and chugging the numbers into an exact equation like P(H|E) = [P(H) × P(E|H)] / [P(H) × P(E|H) + P(¬H) × P(E|¬H)] can be cumbersome. When searching, I found that there were some other Bayesian calculators online, but I felt that they were limited in how much input could be made, or how intuitive they were to use, or how fast they worked. So I set out to create a tool where I could easily calculate probabilities and add multiple pieces of evidence and tweak values, with instant results at every change. Hence, my Bayesian Calculator for Updating Probability with Multiple Conditionally Independent Variables.
Link to this entry on my portfolio:
When I was satisfied that the calculator was working well and could be a fun and useful tool for others, I finally set it up to be published and accessible online. Check out the Bayesian calculator here!