Get startedGet started for free

Hypothesis test: can this be by chance?

The EDA and linear regression analysis is pretty conclusive. Nonetheless, you will top off the analysis of the zigzag effect by testing the hypothesis that lane assignment has nothing to do with the mean fractional difference between even and odd lanes using a permutation test. You will use the Pearson correlation coefficient, which you can compute with dcst.pearson_r() as the test statistic. The variables lanes and f_13 are already in your namespace.

This exercise is part of the course

Case Studies in Statistical Thinking

View Course

Exercise instructions

  • Compute the observed Pearson correlation coefficient, storing it as rho.
  • Initialize an array to store the 10,000 permutation replicates of rho using np.empty(). Name the array perm_reps_rho.
  • Write a for loop to draw the permutation replicates.
    • Scramble the lanes array using np.random.permutation().
    • Compute the Pearson correlation coefficient between the scrambled lanes array and f_13. Store the result in perm_reps_rho.
  • Compute and print the p-value. Take "at least as extreme as" to be that the Pearson correlation coefficient is greater than or equal to what was observed.

Hands-on interactive exercise

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

# Compute observed correlation: rho
rho = ____

# Initialize permutation reps: perm_reps_rho
perm_reps_rho = ____

# Make permutation reps
for i in range(10000):
    # Scramble the lanes array: scrambled_lanes
    scrambled_lanes = ____
    
    # Compute the Pearson correlation coefficient
    ____[i] = ____
    
# Compute and print p-value
p_val = ____(____ >= ____) / 10000
print('p =', p_val)
Edit and Run Code