Must-read Guide to Hypothesis Tests You Will Never Use

Original Source Here
Hypothesis Testing Pipeline
So far, we have talked about the first two steps of hypothesis testing:
- setting up the null and alternative
- identify error types and set a significance threshold
Now, we will look at a simple scenario using Python code.
Below, we have the tips dataset from Seaborn which contains 244 records of clients coming to a restaurant. The dataset records bill and tip amount, table size, and other details. For simplicity, imagine you are the owner of the restaurant and the dataset holds the information for a single workday:
All libraries are imported with their standard aliases.
You calculate the average income for this day by dividing the results into two groups, dinner and lunch:
Looks like on average, dinner-time clients paid more. Now, you wonder if this is just a random event specific to this day, or does this mean all future clients pay more for dinner? Let’s check this using a hypothesis test.
Since we want to prove that dinnertime clients pay more, it will be the alternative:
Performing this type of hypothesis test is called a two-sample test because we have two samples: for lunchtime and dinnertime. So, you will often see the null and alternative of two samples tests stated like this:
The next step is to set the alpha threshold. 5% is the best option. Then, we will simulate the data under the null. In our case, it would be bootstrapping the two samples many times and in each iteration, find the difference in means.
In other words, we obtain a sampling distribution of the difference in means. If you are not familiar with sampling distributions or bootstrapping in general, consider reading my humble introduction to the topics.
First, let’s store the total bill of the two mealtimes in arrays:
FYI, here is the difference between the means:
>>> dinner.mean() - lunch.mean()3.628
Now, we bootstrap the two samples to find many differences in means:
Plotting the sampling distribution will reveal that it follows a normal distribution:
Now, to find out whether the null is true or not, we will find the proportion of values that are equal to or lower than 0. Because our null was:
This can be calculated with simple arithmetic:
np.sum(diffs <= 0) / len(diffs)0.0003
We find the number of differences that are equal to or lower than 0 and divide by the length of the sampling distribution.
This gives us a 0.0003 probability of having a difference in mean lower than or equal to 0. What does this mean?
Well, it means that we should reject the null. Because we said the mean income from lunchtime was the same or greater than dinnertime. And we simulated the data under this assumption and when we calculated the probability of that happening, we got 0.03% or 3 out of every 10000 days.
Based on this, we reject the null and accept the alternative which states that dinnertime clients pay more on average than lunchtime clients.
This was a simple example of hypothesis tests. For your reference, I will leave out the full pipeline:
- Find out what you want to test
- State relevant null and alternative hypotheses
- Set a significance level — alpha (𝛼)
- Simulate the data under the null for your test statistic (in our case, we used mean)
- Draw conclusions from the results
AI/ML
Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot
via WordPress https://ramseyelbasheer.wordpress.com/2021/01/31/must-read-guide-to-hypothesis-tests-you-will-never-use/