My aim is to write an advanced maths book that uses just pictures :) This is my attempt for the concepts of covariance and precision.
Example 1: Student IQs
Let's take a class of 100 students and take 10 measurements for each of them. This measurement data is Gaussian in its distribution. Then, our data looks like this:
Data Heatmap |
[Python code lives here].
We can see each student's measurements roughly conforms to a value but there is a large variety over all the students.
Now, we build the covariance matrix where:
- the expected value (mean) for a row is subtracted from each value in the vector
- the resulting vector is multiplied with all the other vectors and this forms the index for our matrix
- each cell is multiplied by the probability of that combination occuring. It's perfectly possible that this is zero in some cases but for our use case the distribution of which student and which measurement we might chose is uniform.
Note, regarding covariance as a measurement:
"Covariance is useful in some computations, but it is seldom reported as a summary statistic because it is hard to interpret. Among other problems, its units are the product of the units of X and Y. So the covariance of weight and height might be in units of kilogram-meters, which doesn’t mean much" - Think Stats
Anyway, our covariance matrix looks like this:
Covariance matrix heatmap |
- each row has a strong covariance with itself (the diagonal)
- that the matrix is symmetric (since the covariance formula is symmetric)
- and that all other cells than the diagonal are just noise.
The inverse of the covariance matrix is called the precision matrix. It looks like this:
Precision matrix heatmap |
To illustrate this, I've written some Python code based on this excellent post from Prof Matthew Stephens. He asks us to imagine a random walk where on each step we add the value from a Gaussian distribution. The output might look like this:
Random walk |
Covariance Matrix of the Random Walk |
Precision Matrix of a Markov Chain |
and this gives us an intuitive feeling for what the precision matrix is all about "The key property of the precision matrix is that its zeros tell you about conditional independence. Specifically [its values are] 0 if and only if Xi and Xj are conditionally independent given all other coordinates of X." [here] And this is what we see here. Each point is only dependent on its immediate neighbour - the very definition of a Markov process.
No comments:
Post a Comment