Let and be two random variables. The covariance between and is defined as:
Let the vector be defined like so: . Thus,
is a vector of random variables.
The covariance matrix for is defined as:
Where the expectation is an elementwise operation. The covariance matrix is a result of a matrix multiplication of two vector-like matrices, which produces a 2x2 matrix. (Yes, it is valid!).
Matrix interpretation
An intepretation of such a 2x1*1x2 matrix multiplication is:
The first matrix can be considered a transformation matrix which transforms a single dimension into 2 dimensions.
is the factor by which the input scalar is multiplied by to produce the first output dimension;
is the same quantity for the second output dimension. The matrix can
be considered a list of two separate scalars that will be transformed separately.
For the case of , if has dimensions, then the output is D vectors combined horizontally into
a matrix, where each vector is the original multiplied by one of it's components.
For the 2 dimensional covariance matrix we have:
The covariance matrix is symmetric, like all matrixes of the form . Its diagonal is the variances of each random variable.
Random variable interpretation
Covariance is the expected value of the random variable . Imagine the probability mass function of and , then and , then the 2 dimensional , then finally the 1 dimensional . The covariance is a single value representing the expectation (product sum) of the value-probabilities of .