Get startedGet started for free

Hypothesis test: Do women swim the same way in semis and finals?

Test the hypothesis that performance in the finals and semifinals are identical using the mean of the fractional improvement as your test statistic. The test statistic under the null hypothesis is considered to be at least as extreme as what was observed if it is greater than or equal to f_mean, which is already in your namespace.

The semifinal and final times are contained in the numpy arrays semi_times and final_times.

This exercise is part of the course

Case Studies in Statistical Thinking

View Course

Exercise instructions

  • Set up an empty array to contain 1000 permutation replicates using np.empty(). Call this array perm_reps.
  • Write a for loop to generate permutation replicates.
    • Generate a permutation sample using the swap_random() function you just wrote. Store the arrays in semi_perm and final_perm.
    • Compute the value of f from the permutation sample.
    • Store the mean of the permutation sample in the perm_reps array.
  • Compute the p-value and print it to the screen.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Set up array of permutation replicates
perm_reps = ____

for i in range(1000):
    # Generate a permutation sample
    semi_perm, final_perm = ____
    
    # Compute f from the permutation sample
    f = (____ - ____) / ____
    
    # Compute and store permutation replicate
    perm_reps[i] = ____

# Compute and print p-value
print('p =', ____(____ >= ____) / 1000)
Edit and Run Code