Permutation test on frog data
The average strike force of Frog A was 0.71 Newtons (N), and that of Frog B was 0.42 N for a difference of 0.29 N. It is possible the frogs strike with the same force and this observed difference was by chance. You will compute the probability of getting at least a 0.29 N difference in mean strike force under the hypothesis that the distributions of strike forces for the two frogs are identical. We use a permutation test with a test statistic of the difference of means to test this hypothesis.
For your convenience, the data has been stored in the arrays force_a
and force_b
.
Este ejercicio forma parte del curso
Statistical Thinking in Python (Part 2)
Instrucciones de ejercicio
- Define a function with call signature
diff_of_means(data_1, data_2)
that returns the differences in means between two data sets, mean ofdata_1
minus mean ofdata_2
. - Use this function to compute the empirical difference of means that was observed in the frogs.
- Draw 10,000 permutation replicates of the difference of means.
- Compute the p-value.
- Print the p-value.
Ejercicio interactivo práctico
Pruebe este ejercicio completando este código de muestra.
def diff_of_means(data_1, data_2):
"""Difference in means of two arrays."""
# The difference of means of data_1, data_2: diff
diff = ____
return diff
# Compute difference of mean impact force from experiment: empirical_diff_means
empirical_diff_means = ____
# Draw 10,000 permutation replicates: perm_replicates
perm_replicates = draw_perm_reps(____, ____,
____, size=10000)
# Compute p-value: p
p = np.sum(____ >= ____) / len(____)
# Print the result
print('p-value =', p)