Hypothesis test: Are beaks deeper in 2012?
Your plot of the ECDF and determination of the confidence interval make it pretty clear that the beaks of G. scandens on Daphne Major have gotten deeper. But is it possible that this effect is just due to random chance? In other words, what is the probability that we would get the observed difference in mean beak depth if the means were the same?
Be careful! The hypothesis we are testing is not that the beak depths come from the same distribution. For that we could use a permutation test. The hypothesis is that the means are equal. To perform this hypothesis test, we need to shift the two data sets so that they have the same mean and then use bootstrap sampling to compute the difference of means.
This exercise is part of the course
Statistical Thinking in Python (Part 2)
Exercise instructions
- Make a concatenated array of the 1975 and 2012 beak depths and compute and store its mean.
- Shift
bd_1975
andbd_2012
such that their means are equal to the one you just computed for the combined data set. - Take 10,000 bootstrap replicates of the mean each for the 1975 and 2012 beak depths.
- Subtract the 1975 replicates from the 2012 replicates to get bootstrap replicates of the difference.
- Compute and print the p-value. The observed difference in means you computed in the last exercise is still in your namespace as
mean_diff
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Compute mean of combined data set: combined_mean
combined_mean = ____(____((bd_1975, bd_2012)))
# Shift the samples
bd_1975_shifted = ____
bd_2012_shifted = ____
# Get bootstrap replicates of shifted data sets
bs_replicates_1975 = ____
bs_replicates_2012 = ____
# Compute replicates of difference of means: bs_diff_replicates
bs_diff_replicates = ____
# Compute the p-value
p = np.sum(____ >= ____) / len(____)
# Print p-value
print('p =', p)