What is Hypothesis Testing and how do we use it?
Actually, you already use it
Suppose you meet someone for the first time, and they tell you that they can run at 10 km per hour (or just under 7 miles per hour, for those three nations that still use this system).
Hint: average top running speed women ~ 10km/hr, and men ~ 12.8km/hr
You might think, okay, that's close to average; that sounds reasonable.
Now if they said they can run as fast as 30km/hr. Now that's a bit of a stretch.
The average professional sprinter could sustain speeds of 24km/hr, so 30km/hr is improbable, but not impossible since Usain Bolt tops out at a whopping 44km/hr during his Olympic record run.
Some people might say, nahhh, that's too far a stretch, but you might choose to believe them for now.
But if they said they could reach more than 50km/hr. Is it possible? Sure, they might be a hidden Olympic record-shattering machine, an athletic monster like nothing the world has seen before, but at this point, the chances are so slim that you'd reason, that at this point, they're just screwing with you.
So, as humans, we have a general idea of how to tell the truth apart from lies. You start with some baseline, like knowing that average running speeds, and if they are within a reasonable range from the average, you say, okay, that's probable and I'll believe that. If they are wayyy off, like 50km/hr, then you could pretty confidently deduce that they are not telling the truth.
But the question is, how far off do they need to be from the average for you to no longer believe them? Like in the story, 30km/hr is much faster than the average, but people have achieved speeds above that. So, in that case, should you still believe them?
Let's just say, suppose we managed to collect the top running speeds of everyone in the world. And suppose more than 10% of the population can run at or faster than 30km/hr. Then, technically, if you were to random pluck a person out of everyone in the world, then there's a 10% chance that this person could, in fact, reach speeds of 30km/hr.
You might say, that's quite a small chance. But as statisticians, we like to be really sure before we start challenging their statement. To us, 10% chance is still a decently high chance as far as we're concerned.
So what is considered too small of a chance? Collectively, we've decided, 5%. So, if less than 5% of the world can run at or over 30km/hr, then at random, there would less than a 5% chance that you would find someone who could reach that pace. That, we say, is too improbable for us to believe that the person you're talking to just so happens to be part of that small 5% of people with extraordinary running abilities. It's much more likely, with a chance 95% in fact, that the person cannot reach that speed.
Can we still be wrong? Yes, but the chances are so low that, at this point, we conclude that he's not telling the truth.
Let me tell you about Benjamin
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
runs = np.random.rand(100000).reshape(10000, 10) > 0.5
heads = np.sum(runs, axis = 1)
# Label the heights of the bars
counts, bins, patches = plt.hist(heads, bins=11)
for i in range(len(patches)):
plt.annotate(str(int(counts[i])),
xy=(patches[i].get_x() + patches[i].get_width() / 2,
patches[i].get_height()),
ha='center',
va='bottom')
# Create a histogram plot of the data using seaborn
sns.histplot(data=heads, bins=11)
plt.show()
To summarize, we started by giving him the benefit of the doubt (trust that his coin was fair), then we did lots of trials and put our trial results in a cool graph that shows how often a certain outcome occurs (called a distribution), and then counted the number of times that this situation or more extreme (getting 9 heads or more out of 10 times) could occur, divided that by the total number of trials to get probability, and showed that it was so rare (0.1% chance, which is less than 5%, our threshold), that it would happen, that I refuse to believe that the coin was fair to begin with.
And that, is hypothesis testing.
Note from Author
Some of the math-savvy folks in the audience might have realized that we could treat 10 flips as a sequence, e.g. [head, tail, head, head, tail, tail, head, ...] and so on for 10 elements. Then, since each sequence is equally likely to happen, to get the probability of 9 heads, we just need to count the number of sequences that contain 9 heads and divide that by the total number of sequences.
which is equivalent to our simulation result of 0.0098 from before, saving us the need to simulate.
To that I say, good job, now get the fuck out of here. This post isn't for you.
Comments
Post a Comment