easystats / correlation

:link: Methods for Correlation Analysis
https://easystats.github.io/correlation/
Other
436 stars 56 forks source link

(Regularized) (partial) correlations adjusted for random effects #10

Closed DominiqueMakowski closed 5 years ago

DominiqueMakowski commented 5 years ago

I woke with this thing in mind, so I put it here for future reference.

I am currently working on some survey data, with a factor analysis part and exploring some psychometric networks.

Both of these are based more or less based on some kind of correlation matrices. However, Factor analysis requires, to my knowledge (?), a "regular" correlation matrix whereas the second (see all the work by @SachaEpskamp) is often based on partial correlations (or regularized partial correlations obtained for example via LASSO reg).

Here's the thing. My data contain some factors, or grouping structure, which I'd like somehow to adjust the correlations for. However, to my knowledge, there is no package or function that gives "random-effects (partial) correlation matrices".

Our recent discussion on effectsize made salient the fact that you can extract partial correlations in a quite straightforward way from linear regression models. HENCE, I wonder if it would be possible to apply the same to linear mixed models to extract partial correlations "adjusted" for random effects?

Also, I wonder if there's a way to recover the full correlation matrix from such mixed model, which could be in turn useful for EFA.

SachaEpskamp commented 5 years ago

Hi Dominique!

The Gaussian network models are, like factor models and SEM, just a model for the covariance structure. That is, they take covariances/correlations as input, and model them (in this case via partial correlations). See https://link.springer.com/article/10.1007/s11336-017-9557-x. So most functions, including all the ones in psychonetrics.org, can take a correlation matrix as input.

Best, Sacha

mattansb commented 5 years ago

Our recent discussion on effectsize made salient the fact that you can extract partial correlations in a quite straightforward way from linear regression models. HENCE, I wonder if it would be possible to apply the same to linear mixed models to extract partial correlations "adjusted" for random effects?

Just to note that if you apply the F/t to pes functions in a linear mixed model, you get something a kin to the following ratio: ηp2 = SSeffect / (SSeffect + SSindividual differences in the effect)

So make sure that's the "variance explained" you want.

DominiqueMakowski commented 5 years ago

These past few days I spent quite some time refactoring this package from scratch. I believe it is now way more stable, flexible and powerful. Aside from different new features (AFAIK it is the only package being able to compute full Bayesian partial correlations), it also opened the way for this thing I had in mind, that could be called "hierarchical (or multilevel) correlations".

See README here

The idea in a nutshell is to compute partial correlations using mixed models that have factors as random intercepts, and then convert these to regular correlations.

This might be seen as an utter sin or complete dark magic. Of course it would need some kind of exploration to see if it is valid, and if it can be useful. Feel free to try, explore and provide feedback, fixes and improvements :)

mattansb commented 5 years ago

@DominiqueMakowski are these "hierarchical (or multilevel) correlations" correlations were the random intercepts variability is partial-ed out? This sounds like repeated-measures correlations (paper, r pkg)?

DominiqueMakowski commented 5 years ago

This sounds like repeated-measures correlations (paper, r pkg)?

THIS IS WHAT I'VE BEEN LOOKING FOR why didn't you tell me earlier ^^

DominiqueMakowski commented 5 years ago

omg I've spent days to wrap my head around how to do/implement that, while I coulda just google the right name "repeated measures correlations" 😅

DominiqueMakowski commented 5 years ago

Wait no, in fact it seems that in their model it is based on a simple LM (see here), whereas we model the factor(s) as random effects.

mattansb commented 5 years ago

From my testing, it gives the same results as an LMM with:

  1. X is centered by subject.
  2. Y has a random intercept.