donaldRwilliams / BGGM

Bayesian Gaussian Graphical Models
https://donaldrwilliams.github.io/BGGM/
GNU General Public License v2.0
54 stars 14 forks source link

Feature Request: Comparison of node predictability (r2) across samples #74

Closed gloriathan closed 3 years ago

gloriathan commented 3 years ago

Hi, I'm wondering if it would be possible to add an extension to the network comparison functions in bggm to do nodewise comparison of node predictability between two networks/samples (e.g., male vs. female, depressed vs. non-depressed). Thank you!

donaldRwilliams commented 3 years ago

hi. thank you for opening the issue. It is much more convenient to provide code here. I did actually have a function in the package to compare R2, but removed it. That said, it can be done as follows

library(BGGM)
dat <- na.omit(BGGM::bfi)
g1 <- subset(dat, gender == 1)[,1:10]
g2 <- subset(dat, gender == 2)[,1:10]

fit1 <- estimate(g1) 
fit2 <- estimate(g2)

r21 <- predictability(fit1, iter = 500)
r22 <- predictability(fit2, iter = 500)

r2_diff <- 
sapply(1:ncol(g1), function(x){
  quantile(r22$scores[[x]] - r21$scores[[x]], c(0.025, 0.975))
} )

t(r2_diff)

That provides 95 % intervals for the predictability difference.

Ill add a function to do this in the future.

gloriathan commented 3 years ago

Thank you so much!

donaldRwilliams commented 3 years ago

No problem.