Bootstrap hypothesis test on bee sperm counts
Now, you will test the following hypothesis: On average, male bees treated with neonicotinoid insecticide have the same number of active sperm per milliliter of semen than do untreated male bees. You will use the difference of means as your test statistic.
For your reference, the call signature for the draw_bs_reps()
function you wrote in chapter 2 is draw_bs_reps(data, func, size=1)
.
This exercise is part of the course
Statistical Thinking in Python (Part 2)
Exercise instructions
- Compute the mean alive sperm count of
control
minus that oftreated
. - Compute the mean of all alive sperm counts. To do this, first concatenate
control
andtreated
and take the mean of the concatenated array. - Generate shifted data sets for both
control
andtreated
such that the shifted data sets have the same mean. This has already been done for you. - Generate 10,000 bootstrap replicates of the mean each for the two shifted arrays. Use your
draw_bs_reps()
function. - Compute the bootstrap replicates of the difference of means.
- The code to compute and print the p-value has been written for you. Hit submit to see the result!
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Compute the difference in mean sperm count: diff_means
diff_means = ____
# Compute mean of pooled data: mean_count
mean_count = ____
# Generate shifted data sets
control_shifted = control - np.mean(control) + mean_count
treated_shifted = treated - np.mean(treated) + mean_count
# Generate bootstrap replicates
bs_reps_control = ____(____,
np.mean, size=10000)
bs_reps_treated = ____(____,
np.mean, size=10000)
# Get replicates of difference of means: bs_replicates
bs_replicates = ____
# Compute and print p-value: p
p = np.sum(bs_replicates >= np.mean(control) - np.mean(treated)) \
/ len(bs_replicates)
print('p-value =', p)