easystats / datawizard

Magic potions to clean and transform your data 🧙
https://easystats.github.io/datawizard/
Other
211 stars 15 forks source link

multilevel correlation for varying slopes #203

Open btcrewther opened 2 years ago

btcrewther commented 2 years ago

It would be useful to compute the multilevel correlation as a random intercept & random slope mixed-effects model, which allows ID slopes to vary. This option, along with the current approach (random-intercept only model), ensures greater user flexibility.

bwiernik commented 2 years ago

The partial and mulitlevel arguments are intended to facilitate basic adjustment for variables (partial correlations). For more complex or bespoke modeling, I recommend fitting a mixed effects model directly using a full-featured package such as lme4, glmmTMB, or brms.

DominiqueMakowski commented 2 years ago

For more complex or bespoke modeling, I recommend fitting a mixed effects model directly

Agree with that

That said, we could also use that opportunity to add more flexibility to the underlying function datawizard::adjust

https://github.com/easystats/datawizard/blob/e35420bf66d9b2cd2ba949b4b45ae352986f35ba/R/adjust.R#L108-L110

Currently the multilevel argument is FALSE / TRUE and if TRUE sets up random intercepts.

We could allow for multilevel="intercept" (same as TRUE) + multilevel="full" (slopes + intercept), in which case it will add the effect as a random slope

bwiernik commented 2 years ago

The multilevel argument itself is misleadingly named IMO. I would expect it to decompose correlations into within and between components. Instead, it adjusts for person factors, either with or without partial pooling. I don't really understand the use for the results it currently reports.

DominiqueMakowski commented 2 years ago

It's mostly used in the case of multilevel correlations afaik, with the common usecase being to somewhat take into account some grouping factors. Obviously not ideal, but can be useful in exploratory analyses (and I've heard via various sources that it could be quite a popular feature of correlation).

In that context, having a "full" random effect specification y ~ x + (x | g) is not unreasonable i think

bwiernik commented 2 years ago

It's mostly used in the case of multilevel correlations

I don't know what you mean. When I hear "multilevel correlation", I think the within/between correlations computed by eg https://www.rdocumentation.org/packages/psych/versions/2.2.5/topics/statsBy

What we currently compute is neither within nor between

DominiqueMakowski commented 2 years ago

right, I meant correlation partialized via mixed/multilevel models (https://github.com/easystats/correlation#multilevel-correlations)

bwiernik commented 2 years ago

What I'm trying to say is that I don't understand what quantity such a estimator is estimating. What is the context in which this quantity is used?

DominiqueMakowski commented 2 years ago

it then converts the coefficients to "partialized" correlations, and is used as such

IndrajeetPatil commented 2 years ago

Why is this back in datawizard, @DominiqueMakowski? I thought this was about correlation analysis?

DominiqueMakowski commented 2 years ago

Adjust was always in datawizard