I have a few hundred variables representing different biomarkers. These variables have been measured in both cases and controls. The underlying units of measurement are not important, so I have standardized all variables (subtract mean, divide by SD). The standardization was done separately in cases and in controls, since the two groups are expected to have different means for some of the measurements. Within a group, most variables followed a normal distribution, a few that did not were log-transformed to get them closer to normal before standardizing (those variables can be left out if necessary).

Some variables will correlate with each-other in both controls and cases. Other variables may differ in the patterns of correlation they show with each-other in cases vs. controls. Correlations present in both cases and controls can be thought of as noise that I want to remove, so I can get only the case-specific correlations.

My end goal is to look for sets of markers that tend to group together in cases (using a method like factor analysis or PCA).

My original idea was to subtract the covariance matrix for controls from the covariance matrix for cases. But as pointed out in the comments on this question, that won't work because it has the potential to produce negative variances in some of the cells. (Or in this case, since the covariance matrix for standardized variables is a correlation matrix, subtracting would produce 0s on all the diagonals.)

Is there a better approach to take to look at the question "Are there groups of variables that tend to be correlated with each-other specifically in cases, after accounting for any patterns that cases share with controls"?

  • 2
    $\begingroup$ Definitely not, because subtraction can yield negative covariances. It's always more effective to explain what your problem is and ask for solutions rather than asking whether a proposed solution might work! Consider editing your post accordingly. $\endgroup$
    – whuber
    Mar 21, 2023 at 20:27
  • $\begingroup$ @whuber Negative covariances doesn't sound like a problem per se. Did you mean negative variances? (I.e. specifically negative values on the diagonal of the covariance matrix) $\endgroup$
    – Galen
    Mar 21, 2023 at 20:33
  • 1
    $\begingroup$ Certainly you can take the difference between covariance matrices, but as whuber is suggesting the result may not be a valid covariance matrix. Same holds for correlation matrices as a special case. $\endgroup$
    – Galen
    Mar 21, 2023 at 20:35
  • $\begingroup$ Is there some other better approach I should use? The goal is to look for relationships between the variables that happen only in cases and not in controls. $\endgroup$
    – bluemouse
    Mar 21, 2023 at 20:58
  • $\begingroup$ Can you tell us more about the design? There isn't a design-agnostic approach I can recommend. $\endgroup$
    – Galen
    Mar 21, 2023 at 21:04

3 Answers 3


Suppose the control data matrix is $Z$ and for tidyness suppose that each column has mean zero. Let the control correlation matrix is $R$ and assume it is not singular. Let $R^{-1/2}$ be a square root of the inverse of $R$. The matrix $R^{-1/2}Z$ has uncorrelated columns; its correlation matrix is the identity, $R^{-1/2}RR^{-1/2}$

Now let $Y$ be the case data matrix, also with each column centred at zero. The matrix $R^{-1/2}Y$ would have uncorrelated columns if the correlations were the same, so its correlation matrix is a summary of the 'extra' correlations in the cases.

Note that if we write $S$ for the correlation matrix of $Y$, $R^{-1/2}SR^{-1/2}$ is symmetric with non-negative eigenvalues and so is suitable for PCA. Or you could just do singular-value decomposition on $R^{-1/2}Y$.

(I think I'd actually prefer doing this with covariances rather than correlations, so that differences in variance between the two groups don't look like differences in correlation)

  • $\begingroup$ Thank you! I put together some toy R code to try this out (using covariance like you suggested), but I am getting some weird results. When I do π‘…βˆ’1/2π‘†π‘…βˆ’1/2 I I get non-zero covariances in places where covariance was close to 0 for both cases and controls. Is π‘…βˆ’1/2π‘†π‘…βˆ’1/2 still supposed to look like a covariance matrix (eg. have 0s in places where I'd expect 0 covariance)? (Code won't fit in comment: pastebin.com/xLQrX8Sp ) $\endgroup$
    – bluemouse
    Apr 12, 2023 at 22:18
  • $\begingroup$ I also tried a version of the code that didn't standardize the variables for cases and controls, and another version that just centered but did not scale, and both of those still had covariances that should be close to 0 not close to 0 in π‘…βˆ’1/2π‘†π‘…βˆ’1/2. $\endgroup$
    – bluemouse
    Apr 12, 2023 at 22:29

A raw, untested thought. Maybe try this. It seems to me that your interest requires to do factor analysis first.

Do FA on control sample matrix. (I would perhaps recommend to do all the analysis on correlations rather than on covariances because differences in variances between case and control samples may be of lesser importance than differences in correlational patterns.). So, factor correlations of the control sample and arrive at a satisfying interpretable solution (you will need a rotation to interpret the common factors.).

Get the matrix of restored correlations.

Subtract those from the correlations of the case sample. Perform FA of the obtained "residual" or remnant correlations. You essentially "wash out" the factor (= correlational) pattern of controls from the cases, and factor analyse what's left. But what's left is a mixture of the pattern unique for the cases and the noise (nuisance factors) unique of the case sample.

One tricky moment of the subtraction is whether to subtract the diagonal elements too or to leave 1s there. One has to think over this. My immediate, inconclusive thought is to leave 1s. So that in the 2nd FA we do not restrict communalities by the uniquenesses from the 1st one.

A modified approach may be to do the 1st FA on the pooled correlation matrix instead of the correlation matrix of controls. Less contrasting results are expected, because now we reason the "common pattern" as extracted from both sides rather than from one specific side.

  • $\begingroup$ any R dummy example? for this I did PCA but not FA analysis as such $\endgroup$
    – PesKchan
    Apr 8, 2023 at 11:27
  • $\begingroup$ Can you clarify what you mean by "So, factor correlations of the control sample and arrive at a satisfying interpretable solution (you will need a rotation to interpret the common factors.). Get the matrix of restored correlations."? What are the restored correlations and what makes them preferable to the original correlations from controls? $\endgroup$
    – bluemouse
    Apr 12, 2023 at 19:54
  • $\begingroup$ The restored or predicted correlations AA' are what owe to the factors completely. (A is the matrix of factor loadings.). An original correlation is the observed one. It minus the predicted is the residual not explained by the factor structure A, the deviation from the factor structure. $\endgroup$
    – ttnphns
    Apr 13, 2023 at 5:38

A slightly different approach I believe would work here is

  • Transform your correlation matrices using the inverse hyperbolic tangent (artanh) function (the Fisher transformation)
  • Calculate the difference, $\Delta$, between your two artanh transformed correlation matrices.
  • On the artanh scale, the standard error of each correlation coefficient is $\frac{1}{N-3}$. The standard error of the $\Delta$ is therefore $\sqrt{se_1^2 + se_2^2}$.
  • Divide $\Delta$ by its standard error to obtain z-statistics.
  • Any z statistic greater than $2$ in absolute value is statistically significant at $p < .05$ (although adjustment for multiple comparisons is probably appropriate here).
  • $\begingroup$ If my goal isn't to significance-test individual correlations, but to use the resulting correlations for PCA or factor analysis, would it be appropriate to use the matrix of z-statistics for that? (I think it would be, but I want to make sure!) $\endgroup$
    – bluemouse
    Apr 12, 2023 at 19:39
  • $\begingroup$ Probably not, I think. The matrices $\Delta$ and $z$ aren't correlation/covariance matrices, so can't be plugged directly into PCA/factor analysis. My approach doesn't really meet your goal, to be honest. $\endgroup$
    – Eoin
    Apr 13, 2023 at 8:55

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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