1
votes

I have a correlation network between some clients. I used qgraph to plot it and now I would like to do some graph analysis by defining clusters , hubs and centrality.

I found this R function in the igraph package edge.betweenness.community that seems to show clusters in an igraph so I converted my qgraph to an igraph but the function didn't work as I have negative correlation values .

Is there another way to do this ?

Many thanks !

2

2 Answers

2
votes

Following answer from @Karolis, the development version of the corrr package does something like this using network_plot(). Here's an example (including installation of current development version):

install.packages("devtools")
devtools::install_github("drsimonj/corrr")
library(corrr)
airquality %>% correlate() %>% network_plot(min_cor = .2)

enter image description here

The plot represents negative correlations with red lines, but clusters the variables based on the correlation magnitude by using the absolute values of the correlations as the proximity/distance metric. This is handled by the base function abs(). If you think this might help, you can find the relevant code used to produce network_plot() here.

Aside, I'm planning to release the updated version of corrr soon so you can access network_plot() after install straight from CRAN (install.packages("corrr")).

1
votes

One way

Transform your correlations so that -1 will become 0 and 1 still be 1:

cors <- (cors+1)/2

This way negative correlations will be interpreted as "lowest association". If instead -1 and 1 should both be viewed as "association" then you can take the absolute value of your correlation matrix:

cors <- abs(cors)

Another way

Use a different clustering algorithm. One candidate - hierarchical clustering since it operates on a distance matrix. You have a correlation matrix. So to start you should obtain distances:

dists <- as.dist(1-cors)

Then do the clustering:

htree <- hclust(dists)
plot(htree)                # inspect the result visually.
groups <- cutree(htree, 5) # 5 here is desired number of groups.

Also

Check out the package "WGCNA" which stands for "weighted gene coexpression network analysis". It has some useful functions for obtaining clusters out of "network" data.