A bootstrap test for identical distributions
In the video, we looked at a one-sample test, but we can do two sample tests. We can even test the same hypothesis that we tested with a permutation test: that the Frog A and Frog B have identically distributed impact forces. To do this test on two arrays with n1 and n2 entries, we do a very similar procedure as a permutation test. We concatenate the arrays, generate a bootstrap sample from it, and take the first n1 entries of the bootstrap sample as belonging to the first data set and the last n2 as belonging to the second. We then compute the test statistic, e.g., the difference of means, to get a bootstrap replicate. The p-value is the number of bootstrap replicates for which the test statistic is less than what was observed.
Now, you will perform a bootstrap test of the hypothesis that Frog A and Frog B have identical distributions of impact forces using the difference of means test statistic.
This exercise is part of the course
Statistical Thinking in Python (Part 2)
Exercise instructions
- Compute the observed difference in impact force using the
diff_of_means()function you already wrote. - Create an array that is the concatenation of
force_aandforce_b. - Initialize array to store 10,000 bootstrap replicates.
- Write a
forloop to- Generate a bootstrap sample from the concatenated array.
- Compute the difference in means between the first
len(force_a)lastlen(force_b)entries of the bootstrap sample.
- Compute and print the p-value from your bootstrap replicates.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Compute difference of mean impact force from experiment: empirical_diff_means
empirical_diff_means = ____
# Concatenate forces: forces_concat
forces_concat = ____
# Initialize bootstrap replicates: bs_replicates
bs_replicates = ____
for i in ____:
# Generate bootstrap sample
bs_sample = ____
# Compute replicate
bs_replicates[i] = diff_of_means(____,
____)
# Compute and print p-value: p
p = ____ / ____
print('p-value =', p)