Session Ready
Exercise

Hypothesis test on Pearson correlation

The observed correlation between female illiteracy and fertility may just be by chance; the fertility of a given country may actually be totally independent of its illiteracy. You will test this hypothesis. To do so, permute the illiteracy values but leave the fertility values fixed. This simulates the hypothesis that they are totally independent of each other. For each permutation, compute the Pearson correlation coefficient and assess how many of your permutation replicates have a Pearson correlation coefficient greater than the observed one.

The function pearson_r() that you wrote in the prequel to this course for computing the Pearson correlation coefficient is already in your name space.

Instructions
100 XP
  • Compute the observed Pearson correlation between illiteracy and fertility.
  • Initialize an array to store your permutation replicates.
  • Write a for loop to draw 10,000 replicates:
    • Permute the illiteracy measurements using np.random.permutation().
    • Compute the Pearson correlation between the permuted illiteracy array, illiteracy_permuted, and fertility.
  • Compute and print the p-value from the replicates.