7
$\begingroup$

From your experience, do you have any suggestions for representing time-wise changing correlation matrices? I looked at https://quant.stackexchange.com/questions/1565/how-do-i-graphically-represent-the-evolution-of-a-covariance-matrix-over-time, but I couldn't find any good article. I am asking this question because I am fairly new to the field of data analysis, and the only book I have read so far is Wickham's ggplot2. So, I thought of asking experts about it.

I'd sincerely appreciate any help.

$\endgroup$
1
  • 2
    $\begingroup$ The choice of graphical solution strongly depends on your comparison priorities. What is most important for you to compare immediately by glance - element with element within a matrix or element at point t1 with itself at point t2. $\endgroup$
    – ttnphns
    Nov 6, 2016 at 9:49

2 Answers 2

3
$\begingroup$

There are a number of issues here (and whether you use ggplot2 strikes me as entirely orthogonal to them). First, recognize that that correlations don't necessarily scale in an intuitive, 'linear' manner (in large part because their possible range is bounded). It's worth thinking about how you want to represent the values. For example, you could use:

  1. the original correlations ($r$-scores)
  2. coefficients of determination ($r^2$'s)
  3. $z$-scores based on the results of Fisher's '$r$ to $z$' transformation:
    $$z_r = .5\ln\! \bigg(\frac{1+r}{1-r}\bigg)$$

I don't really know anything about your situation, so it's hard for me to say, but my default would be to use the transformed scores ($z_r$).

Next, you need to decide what about the data you want to include (at all, or more or less prominently). For example, do you want to include the absolute magnitudes of the values, or only their changes (cf., levels vs. changes in economics)? Do you primarily care about the magnitudes of the changes (i.e., absolute values), whether they are increases or decreases (the signs, either in an absolute sense, or towards or away from no correlation), or both?

Given that you want to visualize a correlation matrix (i.e., a set of correlations), it is worth remembering that they won't be independent. Consider that a change in only one variable will have an effect on multiple correlations, even if the other variables are constant over time. So again, it depends on whether that matters for you.

In other words, figuring out exactly what you really care about is vital. There won't be a visualization that will capture all of these facets.


From your comment, I gather you will have just two correlation matrices, before and after. That simplifies things. Again, without any information about your situation, data, or goals, I would probably make a scatterplot with before and after on the X-axis, and $z_r$ on the Y-axis, and the two points representing the same correlation joined by a line segment. Consider this example, coded in R:

library(MASS)   # we'll use these packages
library(psych)
set.seed(541)   # this makes the example exactly reproducible
bef = mvrnorm(100, mu=rep(0, 5), Sigma=rbind(c(1.0, 0.0, 0.0, 0.0, 0.0),
                                             c(0.0, 1.0, 0.4, 0.0, 0.5),
                                             c(0.0, 0.4, 1.0, 0.1, 0.0),
                                             c(0.0, 0.0, 0.1, 1.0, 0.8),
                                             c(0.0, 0.5, 0.0, 0.8, 1.0) ))
aft = mvrnorm(100, mu=rep(0, 5), Sigma=rbind(c(1.0, 0.0, 0.0, 0.0, 0.0),
                                             c(0.0, 1.0, 0.4, 0.0, 0.5),
                                             c(0.0, 0.4, 1.0, 0.1, 0.0),
                                             c(0.0, 0.0, 0.1, 1.0, 0.8),
                                             c(0.0, 0.5, 0.0, 0.8, 1.0) ))
aft[,5] = rnorm(100)  # above I generate data 2x from the same population, 
b.c = cor(bef)        #  here I change just 1 variable
a.c = cor(aft)        # then I make cor matrices, & extract the rs into a vector
b.v = b.c[upper.tri(b.c)]
a.v = a.c[upper.tri(a.c)]
d   = stack(list(bef=b.v, aft=a.v))
d$ind = relevel(d$ind, ref="bef")
windows(width=7, height=4)
  layout(matrix(1:2, nrow=1))
  plot(as.numeric(d$ind), fisherz(d$values), main="Fisher's z",
       axes=F, xlab="time", ylab=expression(z [r]), xlim=c(.5,2.5))
  box()
  axis(side=1, at=1:2, labels=c("before","after"))
  axis(side=2, at=seq(-.2,1.5, by=.2), cex.axis=.8, las=1)
  for(i in 1:10){ lines(1:2, matrix(fisherz(d$values), nrow=10, ncol=2)[i,]) }

  plot(as.numeric(d$ind), d$values, main="Raw rs",
       axes=F, xlab="time", ylab="r", xlim=c(.5,2.5))
  box()
  axis(side=1, at=1:2, labels=c("before","after"))
  axis(side=2, at=seq(-.2,1.0, by=.2), cex.axis=.8, las=1)
  for(i in 1:10){ lines(1:2, matrix(d$values, nrow=10, ncol=2)[i,]) }; rm(i)

fdif       = abs(fisherz(a.c)-fisherz(b.c))
diag(fdif) = 0
windows()
  image(1:5, 1:5, z=fdif, 
        xlab="", ylab="", col=gray.colors(8)[8:3])
  for(i in 1:5){ for(j in 1:5){ text(i,j,round(fdif,2)[i,j]) }}

enter image description here

The figures above display both the levels of the correlations and the amount of change. You can see various features, such as a convergence towards $r=0$. The difference between using $z_r$ and $r$ is that the $r$-scores are more uniformly distributed beforehand. The distance between $0$ and $.4$ is the same as the distance between $.4$ and $.8$, for example. On the other hand, for $z_r$, the correlations that are close to $0$ are clumped together and the strong correlation is much further out from the rest. What those figures don't capture is the non-independence of those lines. You can see in the heatmap below (using absolute values of the differences in $z_r$'s) that the larger changes are associated with variable 5.

enter image description here


Update: @whuber has detailed a method to compare covariance matrices based on a new paper (as of 6/2/20) here: Diagnostic plot for assessing homogeneity of variance-covariance matrices

$\endgroup$
1
  • $\begingroup$ Thank you so much for your help. I used Irishstat's answer below for my presentation two days ago. It went well. However, in the future, I will use Fisher's transformation. I like it. $\endgroup$
    – watchtower
    Nov 12, 2016 at 18:57
1
$\begingroup$

In my opinion it is better to quantify the effect of changes in parameters ( a proxy for local correlations ) rather than attempt a visual as attempts at visual comparisons can be quite subjective Your question is similar to "How do I test if the parameters of my model change over time" . What I have done is to program the Chow test to determine at what point in time do the parameters have the greatest divergence. Finding this leads to a direct test of significance possibly yielding the conclusion that "earlier data" should be set aside.

$\endgroup$
4
  • $\begingroup$ What is your answer to the question, which appears to ask about graphical ways to visualize the changes over time? $\endgroup$
    – whuber
    Nov 6, 2016 at 16:38
  • $\begingroup$ I guess I was trying to to tell him about an alternative to graphics which in my opinion a working definition of statistical analysis, $\endgroup$
    – IrishStat
    Nov 6, 2016 at 17:56
  • $\begingroup$ @IrishStat - After carefully doing both i.e. visual comparison vs. quantifying them, I have realized that quantifying them is much better. Essentially, I am going to create two matrices 'before and after' and then show what's going on. Thanks again for your help. $\endgroup$
    – watchtower
    Nov 6, 2016 at 18:44
  • 1
    $\begingroup$ The problem you may have is determining how to specify the break point. The approach I was suggesting can actually determine the most significant break point. Additionally correlations can be severely dampened by anomalies causing you to conclude that there is no relationship. That is why one needs to accomodate/rectify/adjust/cleanse for identifiable anomalies so as correctly assess break points but that's just my two cents opinion. $\endgroup$
    – IrishStat
    Nov 6, 2016 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.