brms icon indicating copy to clipboard operation
brms copied to clipboard

covariance among distinct random effects with the same levels

Open rozdakin opened this issue 6 years ago • 10 comments

Currently, it is not possible to model distinct random effects as correlated across grouping variables.

This could be useful for the case where the same individuals are both focal/subjects and have a social influence on others.

For example:

DATA <- data.frame(
  focalID=rep(as.character(1:100),each=5), 
  alterID=sample(rep(1:100,each=5)), 
  Time=rep(seq(1,5, by=1),100), 
  focalEFFECT=rep(runif(100,10,20),each=5)
)

DATA$alterID <- factor(DATA$alterID)
DATA$focalID <- factor(DATA$focalID, levels=levels(DATA$alterID))
DATA$alterEFFECT <- DATA$focalEFFECT[match(DATA$alterID, DATA$focalID)]
DATA$focalEFFECT <- DATA$focalEFFECT + rep(rnorm(100,0,2), each=5)
DATA$X1 <- DATA$focalEFFECT - DATA$alterEFFECT + rnorm(500,20,5)

library(brms)

set.seed(101)
mod <- brm(X1 ~ Time + (1|ID|focalID) + (1|ID|alterID), data=DATA, cores=1, chains=1, iter=500)

Error: Can only combine group-level terms of the same grouping factors.

rozdakin avatar Aug 18 '18 01:08 rozdakin

Thanks for opening this issue! I agree this would be nice to have.

In terms of automatically writing the Stan code, it should be easily doable. Unfortunately, several parts of brms are currently not prepared for this use case and thus may require a little bit of refactoring. I will take a close look at that.

paul-buerkner avatar Aug 18 '18 08:08 paul-buerkner

Hi Paul: just wondering, is there any chance this is on the horizon?

Many thanks for your software & guidance on this issue.

rozdakin avatar Oct 12 '18 18:10 rozdakin

I haven't started working on it, but my initial assessment that this will require non-negligible amounts of refactoring still holds. Once I have some free time, I will address this and some other issues, but this will likely not happen this year.

paul-buerkner avatar Oct 15 '18 13:10 paul-buerkner

Thank you! I figured as much but needed to verify for peer review.

rozdakin avatar Oct 15 '18 20:10 rozdakin

Hi. I would like to fit the same kind of model as described here. Is it possible now? thanks and cheers

vincent-careau avatar Jun 03 '20 15:06 vincent-careau

Unfortunately not. The "one-group-for-all-correlated-random-effects" approach is very deeply build in and I haven't yet come up with a solution that does not require a complete refactor, which I am unable to do at the moment (and would perhaps also not be worth it given the time it takes). Once I (or someone else) have come up with a solution, that doesn't require a major refactor, I will happly implement it.

paul-buerkner avatar Jun 03 '20 16:06 paul-buerkner

Dear Paul,

I am working on a similar research question as specified above and was wondering whether there is any update on this issue?

Thanks, Benedikt

BenediktHoltmann avatar Nov 11 '21 13:11 BenediktHoltmann

No updates on this issue unfortunately.

Am Do., 11. Nov. 2021 um 14:04 Uhr schrieb BenediktHoltmann < @.***>:

Dear Paul,

I am working on a similar research question as specified above and was wondering whether there is any update on this issue?

Thanks, Benedikt

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/paul-buerkner/brms/issues/502#issuecomment-966285367, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCW2ACNWAEB27VLBVSYHXLULO5MBANCNFSM4FQJPWUA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

paul-buerkner avatar Nov 11 '21 16:11 paul-buerkner

Is there any workaround with non-linear formulas?

StaffanBetner avatar Nov 12 '21 08:11 StaffanBetner

Just mentioning that I'm also interested in this functionality :)

peclayson avatar May 18 '22 12:05 peclayson