hfgolino/EGAnet

How to get modularity after EGA and estimatenetwork

Closed this issue · 2 comments

HI sir,
Im a new hand of EGAnet having uncertainty about this package
my network is constructed by ggmModSelect which is a arguments of 'estimatenetwork' in qgraph
but i saw that EGAnet is using EBICglasso to get community result
Does such a community result make sense for the GGM network? OR can EGA get the community using existing network?

and if I want to calculate modularity Q index in this result, how to set the code's arguments?

here's the code Im using
get ggm network
Stepwise_result<-estimateNetwork(data1,default = ('ggmModSelect'),stepwise = TRUE)
EGA
ega_result<-EGA(data1, plot.EGA = TRUE,corr= "pearson")
OR there is a method to input ggm network result
ega_ggm<-EGAxxx(Stepwise_result, plot.EGA = TRUE)

then calculate modularity
modularity(convert2igraph(ega_result$network),ega_result$wc)
OR
modularity(convert2igraph(Stepwise_result$graph), ega_result$wc)?
OR if the ega_ggm is reasonable, use ega_ggm$wc instead of ega_result$wc

THX a lot for your kind help!!!

Hi @Brooks0303,

Here is a minimal example (using the wmt2 data from {EGAnet}) to use a network estimated elsewhere (e.g., {bootnet}) and use the {EGAnet} workflow to compute modularity:

# Load packages
library(EGAnet); library(bootnet)

# Load data
data <- wmt2[,7:24]

# Estimate network
stepwise_result <- estimateNetwork(
  data = data, default = "ggmModSelect", stepwise = TRUE
)

# Check for unidimensionality
community.unidimensional(data)
# In this example, not unidimensional

# Proceed with multidimensionality
memberships <- community.detection(
  network = stepwise_result$graph, 
  algorithm = "walktrap"
)

# Compute modularity
modularity(
  network = stepwise_result$graph,
  memberships = memberships
)

If you wanted to plot your network + communities, then you can:

# Make custom EGA list
custom_ega <- list(
  network = stepwise_result$graph,
  wc = memberships
)
class(custom_ega) <- "EGA"

# Plot
plot(custom_ega)

For plotting help, please see: https://github.com/hfgolino/EGAnet/wiki/Plots-in-%7BEGAnet%7D

Okay! Ill try to use it in my code, thanks for your kind help!