Covariance and the Pearson correlation coefficient

Statistical Thinking in Python (Part 1)

Justin Bois

Teaching Professor at the California Institute of Technology

2008 US swing state election results

ch2-4_v2.003.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

2008 US swing state election results

ch2-4_v2.004.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

2008 US swing state election results

ch2-4_v2.005.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

Generating a scatter plot

_ = plt.plot(total_votes/1000, dem_share,
             marker='.', linestyle='none')
_ = plt.xlabel('total votes (thousands)')
_ = plt.ylabel('percent of vote for Obama')
Statistical Thinking in Python (Part 1)

Covariance

  • A measure of how two quantities vary together
Statistical Thinking in Python (Part 1)

Calculation of the covariance

ch2-4_v2.011.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

Calculation of the covariance

ch2-4_v2.012.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

Calculation of the covariance

ch2-4_v2.013.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

Calculation of the covariance

ch2-4_v2.014.png

$$covariance = \frac{1}{n}\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})$$

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

Pearson correlation coefficient

$$\rho = \text{Pearson correlation} = \frac{\text{covariance}}{(\text{std of x}) (\text{std of y})}$$

$$= \frac{\text{variability due to codependence}}{\text{independant variability}}$$

Statistical Thinking in Python (Part 1)

Pearson correlation coefficient examples

ch2-4_v2.020.png

Statistical Thinking in Python (Part 1)

Let's practice!

Statistical Thinking in Python (Part 1)

Preparing Video For Download...