Generating permutation replicates
As discussed in the video, a permutation replicate is a single value of a statistic computed from a permutation sample. As the draw_bs_reps()
function you wrote in chapter 2 is useful for you to generate bootstrap replicates, it is useful to have a similar function, draw_perm_reps()
, to generate permutation replicates. You will write this useful function in this exercise.
The function has call signature draw_perm_reps(data_1, data_2, func, size=1)
. Importantly, func
must be a function that takes two arrays as arguments. In most circumstances, func
will be a function you write yourself.
Este exercício faz parte do curso
Statistical Thinking in Python (Part 2)
Instruções de exercício
- Define a function with this signature:
draw_perm_reps(data_1, data_2, func, size=1)
.- Initialize an array to hold the permutation replicates using
np.empty()
. - Write a
for
loop to:- Compute a permutation sample using your
permutation_sample()
function - Pass the samples into
func()
to compute the replicate and store the result in your array of replicates.
- Compute a permutation sample using your
- Return the array of replicates.
- Initialize an array to hold the permutation replicates using
Exercício interativo prático
Experimente este exercício preenchendo este código de exemplo.
def draw_perm_reps(data_1, data_2, func, size=1):
"""Generate multiple permutation replicates."""
# Initialize array of replicates: perm_replicates
perm_replicates = ____
for i in ____:
# Generate permutation sample
perm_sample_1, perm_sample_2 = ____
# Compute the test statistic
perm_replicates[i] = ____
return perm_replicates