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

Exercise

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.

Instructions

100 XP
  • 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.
    • Return the array of replicates.