# Correlation and correlation structure (8) – the precision matrix

If you are reading this, you already know that the covariance matrix represents unconditional linear dependency between the variables. Far less mentioned is the bewitching fact that the elements of the inverse of the covariance matrix (i.e. the precision matrix) encode the conditional linear dependence between the variables. This post shows why that is the case. I start with the motivation to even discuss this, then the math, then some code.

Wide data matrices, where , are widespread nowadays (pun intended). In this situation a good, stable and reliable estimate for the covariance matrix is hard to obtain. The usual sample covariance estimate when is simply lousy (for reasons out of scope here). Much is written about how best to adjust and correct that sample covariance estimate (see below for references). A motivation to shift the focus from the covariance matrix to the precision matrix is how we start.

Contents

### Motivation: thresholding covariance estimation

One glaring issue is that the sample estimate is always dense. I mean, if you simulate data from a population with zero covariance between variables (represented by a diagonal covariance matrix), the sample estimated of the off-diagonal elements will never be exactly zero. This is because the estimated covariance reflects the input data, which will naturally have some variability even if the true underlying covariance is zero. So setting small off-diagonal estimated elements to zero is good thinking, and we call this Thresholding estimation. Let be the element of the sample covariance estimate and let be some threshold value then formally you have the new covariance estimate:

where is the indicator function to return zero if the absolute value is below the you set. Like that we can create a sparse covariance estimate.

Now, each entry in the covariance matrix is independent of other variables. The entry is simply . So for example if drives, and co-move with both , and ; meaning and are both high, then is also likely to be high. If we are able to net-out the movement in from that would be good. In other words we look for . Why would that be good? because is likely to be much lower than , and so threshold makes (even) better sense. We would expect many more zeros if we could find the partial covariances .

### The precision matrix

The precision matrix is the inverse of the covariance matrix. It just so happens that the entries of the precision matrix are exactly what we are looking for, the conditional (on other variables) rather than the unconditional as it is with the covariance matrix. This morning I was walking with a fellow statistician, data scientist, quant, machine learning engineer, AI researcher, statistician, and he challenged me to explain this. I could not do much but accept the challenge. So, why by inverting the covariance matrix we end up with a precision matrix which encodes the conditional dependence any two variables after controlling the rest?

### Some gory details

Consider a data matrix with rows and columns; . Partition to two matrices: first 2 columns as X and the rest as Y. For the sake of simplicity assume that

So

.
The covariance and precision matrice are given by

and

I remind you what are we chasing here. is just a matrix with 2 columns. So the off-diagonal of is just one number. We want to show that this number is the conditional dependence between the two columns, after accounting for all other columns .

The order of things to come:

1. Express in terms of the covariance matrix .
2. Show that is the covariance of the conditional distribution .
3. Relate the result to the more general case of linear projection.
4. Illustrate it with some code.
1. We start by expressing in terms of the covariance matrix :

This expression comes from a tedious matrix algebra or better yet from something we know about this kind of block matrices and their inverse which is called Schur complement.

2. (in the Gaussian case) The Precision matrix is the covariance of the conditional distribution
3.

Usually you see this written in terms of but recall that .

We can ignore anything that is dependent on (specifically ) since we condition on it, so we can treat it as a constant, and keep all terms related to (the rest will go outside the brackets and be elegantly ignored by using the which means “proportional to”):

Using some additional algebra (see below for some rules we need here) we can write it as:

What we are going to do now is to make it look like the normal distribution:

so we recognize the covariance term out of the expression. The trick is to add and remove the same term (preserving the value overall expression), and completing the square, aka “completing the quadratic form”. We have quite a few algebraic rules to remember moving forward: transposing, noting that the covariance is a symmetric matrix, and that we can consider anything which does not depends on X as a constant, even since it does not change with the realization of X. I wrote down some rules we use below and here you can find what I use for verification.

The term we need to add and subtract is to get

So this looks like what we aimed for:

as if and especially if you remember that is itself an inverse (so actually “in the denominator” of that exponent):

Cool cool, but what do we have? that the variance of the conditional distribution of X on Y is an expression, which says that you need to subtract from which you can think of as total variability, the part which is explained by : .

4. The link with linear projection
5. You have seen this in the past:

Recall that when the mean vector is zero, then is the covariance simply (up to a scaling constant). Now observe that the above expression can be thought of (up to a constant) as the coefficient from a regression which explains the column of using the columns of . Specifically, is analogous to the cross-product in regression, capturing the covariance between and . is analogous to in that expression, capturing the covariance within the columns of .

6. Code illustration
7. Here is some R code to replicate the math above. We start by pulling some stock market data using the quantmod package:

We will net-out, or control for, other variables by using the residuals from the node-wise regressions: . So the partial linear dependence between and say will be estimated by .

To cite this blog post “Eran Raviv (2024, June 6). Correlation and correlation structure (8) – the precision matrix. Retrieved on … month, year from https:…”

Footnotes and references

• Fan, Jianqing, Yuan Liao, and Han Liu. “An overview of the estimation of large covariance and precision matrices.” The Econometrics Journal 19, no. 1 (2016): C1-C32.
• Bickel, Peter J., and Elizaveta Levina. “Covariance regularization by thresholding.” (2008): 2577-2604.
• Meinshausen, Nicolai, and Peter Bühlmann. “High-dimensional graphs and variable selection with the lasso.” (2006): 1436-1462.
• Lu, Tzon-Tzer, and Sheng-Hua Shiou. “Inverses of 2× 2 block matrices.” Computers & Mathematics with Applications 43, no. 1-2 (2002): 119-129.
• Some algebra rules which were used

• Reminder for completing the square:

• For positive semi-definite: