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

Connected

Exercise

A two-sample bootstrap hypothesis test for difference of means.

You performed a one-sample bootstrap hypothesis test, which is impossible to do with permutation. Testing the hypothesis that two samples have the same distribution may be done with a bootstrap test, but a permutation test is preferred because it is more accurate (exact, in fact). But therein lies the limit of a permutation test; it is not very versatile. We now want to test the hypothesis that Frog A and Frog B have the same mean impact force, but not necessarily the same distribution. This, too, is impossible with a permutation test.

To do the two-sample bootstrap test, we shift both arrays to have the same mean, since we are simulating the hypothesis that their means are, in fact, equal. We then draw bootstrap samples out of the shifted arrays and compute the difference in means. This constitutes a bootstrap replicate, and we generate many of them. The p-value is the fraction of replicates with a difference in means greater than or equal to what was observed.

The objects forces_concat and empirical_diff_means are already in your namespace.

Instructions

100 XP
  • Compute the mean of all forces (from forces_concat).
  • Generate shifted data sets for both force_a and force_b such that the mean of each is the mean of the concatenated array of impact forces.
  • Generate 10,000 bootstrap replicates of the mean each for the two shifted arrays. Use the draw_bs_reps() function you wrote.
  • Compute the bootstrap replicates of the difference of means by subtracting the replicates of the shifted impact force of Frog B from those of Frog A.
  • Compute and print the p-value from your bootstrap replicates.