# HIDDEN
import warnings
warnings.filterwarnings('ignore')
from datascience import *
from prob140 import *
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
%matplotlib inline
Let’s examine how covariance behaves. In the next two sections we will use our observations to calculate variances of sample sums.
Establishing properties of covariance involves simple observations and routine algebra. We have done some of it below, and we expect that you can fill in the rest.
Covariance is an expected product: it is the expected product of deviations. It can also be written in terms of the expected product of X and Y, as follows.
So covariance is the mean of the product minus the product of the means.
Set X=Y in this result to get the “computational” formula for the variance as the mean of the square minus the square of the mean.
This result simplifies proofs of facts about covariance, as you will see below. But as a computational tool, it is only useful when the distributions of X and Y are very simple – for example, when each has just a few possible values. In other calculations of covariance it is rarely a good idea to try to use this result. Rather, we will use the bilinearity property described at the end of this section.
from IPython.display import YouTubeVideo
YouTubeVideo('_FG4CxA6_9A')
That might look intimidating, but in fact this property greatly simplifies calculation. It says that you can expand covariance like the product of two sums. For example,