hfgolino/EGAnet

Discrepency between results from EGA(x, model = "TMFG") and TMFG(x)

Closed this issue · 3 comments

Hi,

I'm not sure if the following is a bug or not and if its not, I would like an explanation as to why its happening.

I'm trying to build a network using only the negative correlations. In order to do this, I set the positive correlations to 0 and use TMFG to build the network. When using EGA(), the created network always has positive edges in it and I'm not sure why. These edges aren't there when using TMFG() directly. See below for a reproducible example.

library(EGAnet)

set.seed(123)

x <- matrix(rnorm(100), ncol = 20)

corx <- cor(x)

negx <- corx
negx[negx > 0] <- 0
diag(negx) <- 1

egaX <- EGA(negx, n = 20, model = "TMFG", plot.EGA = FALSE)
diag(egaX$network) <- 0

which(egaX$network > 0)

tmfg <- TMFG(negx)
diag(tmfg$A) <- 0

which(tmfg$A > 0)

I see this is probably happening due to Matrix::nearPD being run. I assume the matrix being positive-definite is necessary only for glasso and not TMFG? If so, might it makes sense to run it only if method="glasso"?

@huzefaKhalil,

Thanks for troubleshooting -- you're correct. This difference is due to Matrix::nearPD

The positive-definite component is mainly for GLASSO but should be considered for both. With the GLASSO, the positive-definite requirement is so that that inverse covariance can be computed.

The TMFG matrix should be positive-definite but it does not require it. It simply attaches the largest (absolute) relations to one another so it does not require positive-definite matrices

closing because the difference was identified