## Wednesday, July 11, 2018

### Great Demonstration of Bayes' Theorem

Bayes' theorem is an excellent tool, once you wrap your head around it. In fact, it was discovered as sort of an accident that actually horrified Bayes (and others), and was highly controversial even into the 20th century - to the point that many statisticians eschewed inverse probability and, when they used it, did so in secret.

I've blogged about  and applied it several times:
And I highly recommend a couple books to learn more about Bayes': The Theory that Wouldn't Die and Doing Bayesian Analysis. But this morning, I read an excellent demonstration of Bayes' theorem - what is the probability the post's author is asleep given her bedroom light is on?
I have more than 2 months of data from my Garmin Vivosmart watch showing when I fall asleep and wake up. In a previous post, I figured out the probability I am asleep at a given time using Markov Chain Monte Carlo (MCMC) methods.

This is the probability I am asleep taking into account only the time. What if we know the time and have additional evidence? How would knowing that my bedroom light is on change the probability that I am asleep?

We will walk through applying the equation for a time of 10:30 PM if we know my light is on. First, we calculate the prior probability I am asleep using the time and get an answer of 73.90%. The prior provides a good starting point for our estimate, but we can improve it by incorporating info about my light. Knowing that my light is on, we can fill in Bayes’ Equation with the relevant numbers

The knowledge that my light is on drastically changes our estimate of the probability I am asleep from over 70% to 3.42%. This shows the power of Bayes’ Rule: we were able to update our initial estimate for the situation by incorporating more information. While we might have intuitively done this anyway, thinking about it in terms of formal equations allows us to update our beliefs in a rigorous manner.
She's shared her code for these calculations in a Jupyter Notebook, which you check out here.