1. Learn
  2. /
  3. Courses
  4. /
  5. Statistical Thinking in Python (Part 2)

Connected

Exercise

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.

Instructions

100 XP
  • 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_a and force_b.
  • Initialize array to store 10,000 bootstrap replicates.
  • Write a for loop to
    • Generate a bootstrap sample from the concatenated array.
    • Compute the difference in means between the first len(force_a) last len(force_b) entries of the bootstrap sample.
  • Compute and print the p-value from your bootstrap replicates.