A couple of weeks ago, a student of mine inquired about how the `pos_def_limits()`

function from the `faux`

R package works. This package is being developed by the super awesome Dr. Lisa DeBruine who you should, like, totally follow, btw, in case you are not doing it already. What makes this post interesting is that I thought `pos_def_limits()`

was doing one thing but it is doing something else. I think it helps highlight how different ways of approaching the same problems can give you insight into different aspects of it. But first, some preliminaries:

**What is positive definiteness?**

This one is not particularly complicated to point out. Define as an real-valued matrix and as an real-valued, non-zero vector. Then is a positive-definite matrix if and it is positive-**semi**-definite if for all . I prefer this definition of positive definiteness because it generalizes easily to other types of linear operators (e.g., differentiation) as opposed to *consequences* of this definition, which is what we usually operate on. If you come from the social sciences (like I do) the “version” that you know about a matrix (usually, covariance matrix) being positive-definite is that all its eigenvalues have to be positive. Which is what `pos_def_limits()`

relies on. It implements a grid-search over the plausible correlation range of [-1, +1] and, once it finds the minimum and maximum value for which the set of covariance matrices are all positive definite, it produces a result (or it lets you know if said matrix does not exist, which is super useful as well). Relying on the documentation example:

`pos_def_limits(.8, .2, NA)`

> min max

> -0.427 0.747

which means that if you have a correlation matrix that looks like:

then as long as , your resulting matrix is positive definite and, hence, a valid correlation matrix. So far so good.

**How I tackle this problem**

This is what I thought `pos_def_limits()`

was doing under the hood before looking at the source code. So… a similar condition to the positive eigenvalues is that the determinant of the matrix has to be positive. So **IF** is positive-semi- definite, **THEN **. Notice that this DOES NOT work the other way around: just because does not mean that is positive-semi-definite). Anyway, we can rely on the fact that all correlation/covariance matrices are positive-definite by definition, which means the problem of finding the suitable upper and lower bounds is simply solving for subject to the constraint that the determinant MUST be greater than or equal to zero. So with the help of a CAS (Computer Algebra System, my favourite one is MAPLE because I’m very Canadian, LOL) I can see that solving for results in the following:

which is… A QUADRATIC EQUATION! We can graph it and see:

So that any value on the x-axis between both roots yields a valid inequality and, therefore, a positive-definite matrix . Do you remember how to solve for the roots of quadratic equations? Using our trusted formula from highschool we obtain:

which match the values approximated by `pos_def_limits()`

**Extensions to this problem Pt I: Maximizing the determinant**

There are 2 interesting things you can do with this determinantal equation. First and foremost, you can choose *the* value that maximizes the variance encoded in the correlation matrix . The determinant has a lot of interesting properties, including a very nice geometric representation. The absolute value of the determinant is the volume of the parallelepiped described by the column vectors within the matrix. And this generalizes to higher dimensions. Because correlations are bounded in the [-1, +1] range, the maximum determinant that ANY correlation matrix can have is 1 and the minimum is 0. So if I want my matrix to have the largest possible determinant, I only need to choose the value at the vertex of the parabola:

which has coordinates (0.16, 0.3456). So if then the determinant of is at it maximum.

**Extensions to this problem Pt II: What if more than one correlation is missing?**

The “classical” version of this problem is to have a 3 x 3 matrix where 2 correlations are known and 1 is missing. But (as my student questioned further) what would happen if we had, say a 4 x 4 matrix and TWO correlations were missing? Well, no biggie. Let’s come up with a new matrix, let’s call it with the following form:

Yeah, I had to make up a couple of extra correlations (0.3 and 0.5) to make sure only TWO correlations were missing. But there is a point to this that you will notice very quickly. Since we still want to be a valid correlation matrix, the condition must still hold, irrespective of the dimensions or how many missing elements has. So, once again, running this new matrix through the CAS system yields the condition:

Which generates a system of quadratic inequalities which must be solved simultaneously to yield valid ranges. Rather than showing you the equations (booooooring! :D) let me show you something prettier. A picture of the solution space:

Yup. Any combination of points (a,r) within the red regions would yield a valid solution to the inequality above. HOWEVER, there is only ONE region where the solution is both within the valid (i.e., red) regions AND gives us solutions in the valid correlation range. What does your intuition tell you? I think we both know where to look 😉

That is correct! That little blob-looking thingy is where we want to be at. ANY combination of values within the blob is both between [-1, +1] AND satisfies the determinantal equation so any pair of values STRICTLY inside the blob will yield a valid correlation matrix .

“But Oscar — you may ask– how do we choose the one pair of values that maximizes the determinant of ?” Well, that’s a good question! It is not difficult to answer, but it does require a little more mathematics than the case where only one is missing. What we need is to, first, take the partial derivatives with respect to both r and a and set them to 0 (we need to find maximums):

So now we have a system of quadratic equations. There are two equations and two unknowns so we know this system is just-identified and *has* a solution. Again, when you throw them in MAPLE you end up with multiple values for a and r that maximize . There was only one pair of solutions, though, which was both within the valid range [-1, +1] AND inside the special blob:

The last thing we need to check, however, is whether these points are minimums, maximums or saddle points as per the 2nd derivative test.

Which means I need all the 2nd partial derivatives from the equation above as:

Calculate the discriminant setting a=0.473863 and r=-0.038687 :

Which is greater than 0. So (a,r) are either minimums or maximums. The final check is to see if to make sure it’s a local maximum. And since , then it follows that the point (a,r) indeed maximizes the determinant*****.

**TWO potential future directions **

While working on this I noticed a couple of peculiarities that I think are sufficiently mathematically tractable for me to handle and turn into an actual article. UNLESS you (my dear reader) already know the answer to this. I am, after all, a lazy !@#$#% which means that if someone already worked out a formal proof for it, I’d much rather read it than having to come up with it on my own. Let us start with the easy one:

**(1) (Easy): The range of plausible correlations shrinks as the dimensions of the correlation matrix increase**

This one is, I think, easy to see. Let’s start with the basic 2×2 correlation matrix:

Then if (read as “element of”) then is a valid correlation matrix and only becomes positive-**semi**-definite if either or . But you get the gist, all the valid correlation range applies.

Notice how the range of shrunk for the 3×3 matrix of our example to:

And this fact is independent of what correlation matrix you have. You cannot get any correlation matrix where, given that 2 of them are known, the resulting range of is the full valid interval AND it is still positive definite.

So, what happens if we go back to our 4 x 4 example with ? Just for kicks and giggles, let’s make ? so that we are only left with 1 unknown. The new matrix looks like this:

If we run this new through `pos_def_limits()`

(it can handle any number of dimensions) we get:

`pos_def_limits(.8, .2,.3,.NA, 5,.3)`

> min max

> -0.277 0.734

Yup, the range has now shrunk. But we don’t quite yet know why. Let’s try it now through the determinantal equation:

And solving for the roots of this equation we get:

Yup, same answer. But notice something interesting. The quadratic coefficient has now shrunk from 1 to -0.91. And, if you remember back from high school, you know that the coefficient of the quadratic term dictates how wide or narrow the parabola is so that if it is outside the [0, 1] range the parabola is wider (i.e., the roots are farther apart) and if it it’s within [0, 1] the parabola is narrower (i.e., the roots are closer together). Which prompts me to make the following claim:

*Claim: As the dimensions of the correlation matrix increase arbitrary, the valid range that makes it positive definite shrinks until it collapses to a *single* point. In other words, for a large enough correlation matrix, only ONE value can make it positive definite.*

This one shouldn’t be particularly difficult to prove. All I need to show is that the leading coefficient of the quadratic term shrinks as a function of the dimensions of the correlation matrix until it becomes 0. In which case you’ll have a straight line (not a parabola). And that means you’d get only 1 root (and not 2 that encompass a range).

**(1) (Hard): If I sample values for r from the valid correlation range uniformly, the distribution of the determinants concentrate around *the* value of r that maximizes the determinant. **

This one is a little bit more difficult to explain, but let me show you an interesting thing I found. Let’s use the classic 3 x 3 matrix case and only focus on . We know from above that if then the value of is maximized. Now, let’s use R (the programming language, not the matrix) to uniformly sample random values of it, calculate the determinants and plot them:

n<-10000

r<-runif(n, min=-.427, max=.747)

for (i in 1:n) {

R<-matrix(c(1,.8,.2,.8,1,r[i],.2,r[i],1),3,3)

pp[i]<-det(R)

}

dat<-data.frame(pp)

a<- density(pp)

mmod<-a$x[a$y==max(a$y)]

p<-ggplot(dat, aes(x=pp))+geom_density(fill="lightgreen", alpha=.4, size=1)

p+ geom_vline(aes(xintercept=mmod),

color="red", linetype="dashed", size=1)+theme_bw()+xlab("Determinant")+ylab("")

Compare the mode of the distribution to the theoretical, maximum possible determinant:

>R1<-matrix(c(1,.8,.2,.8,1,.16,.2,.16,1),3,3) > det(R1)

[1] 0.3456

> mmod ##this is the mode of the distribution above

[1] 0.3344818

Close within 0.011 error. Which leads me to make the following claim:

*Claim: For the “missing correlation” problem, the distribution of the determinants of the correlation matrix concentrate around the value of r that maximizes it. *

I honestly have no clue how any of these two results would be useful once they are formalized. I am sensing that something like this may be able to play a role in error detection or diagnosing Heywood cases in Factor Analysis? I mean, for the first case (error detection) say you find a correlation matrix within the published literature that is not positive definite. If correlation matrices tend to concentrate around values that maximize their determinants, then you could potentially use this framework to pick and choose ranges of possible sets of correlations to point out where the problem may lie. A similar logic could be used for Heywood cases, ESPECIALLY if the dimensions of the correlation matrix are large. Or maybe all of this is BS and a very elaborate excuse for me to procrastinate. The world will never know ¯\_(ツ)_/¯