CommencerCommencer gratuitement

Hypothesis test: are they slowing down?

Now we will test the null hypothesis that the swimmer's split time is not at all correlated with the distance they are at in the swim. We will use the Pearson correlation coefficient (computed using dcst.pearson_r()) as the test statistic.

Cet exercice fait partie du cours

Case Studies in Statistical Thinking

Afficher le cours

Instructions

  • Compute the observed Pearson correlation, storing it as rho.
  • Using np.empty(), initialize the array of 10,000 permutation replicates of the Pearson correlation, naming it perm_reps_rho.
  • Write a for loop to:
    • Scramble the split number array using np.random.permutation(), naming it scrambled_split_number.
    • Compute the Pearson correlation coefficient between the scrambled split number array and the mean split times and store it in perm_reps_rho.
  • Compute the p-value and display it on the screen. Take "at least as extreme as" to mean that the Pearson correlation is at least as big as was observed.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Observed correlation
rho = ____

# Initialize permutation reps
perm_reps_rho = ____

# Make permutation reps
for i in range(10000):
    # Scramble the split number array
    scrambled_split_number = ____
    
    # Compute the Pearson correlation coefficient
    ____[i] = ____
    
# Compute and print p-value
p_val = ____(____ >= ____) / ____
print('p =', p_val)
Modifier et exécuter le code