easystats / correlation

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

Error in Multilevel Correlation #280

Closed teindor closed 5 months ago

teindor commented 1 year ago

Hello, I tried using this simple code: wf %>% correlation(select = "inflated", select2 = "gender",multilevel = TRUE) I get this message: Error: No random effects terms specified in formula

I tried tweaking the code like this: wf %>% group_by(id) %>% correlation(select = "inflated", select2 = "gender",multilevel = TRUE) or this: wf %>% correlation(select = "inflated", select2 = "gender",multilevel = TRUE, formula = infalted ~ gender + (1|id), with the same error. I haven't find any explanation here or in the documentation.

The random factor should be "id" Enclosed is the data file Any ideas? wf.csv

mattansb commented 5 months ago

You need to include the grouping variable in select:

wf$id <- factor(wf$id)
correlation::correlation(wf, select = c("id", "inflated", "gender"), multilevel = TRUE)
#> Parameter1 | Parameter2 |    r |            CI | t(539) |     p
#> ---------------------------------------------------------------
#> inflated   |     gender | 0.07 | [-0.02, 0.15] |   1.56 | 0.120
#> 
#> Observations: 541