LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Case Studies in Statistical Thinking

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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)
Code bearbeiten und ausführen