2

I am analysing a directed, weighted network with R igraph. The network is based on a correlation matrix, i.e. weights go from -1 to +1. This network is clearly undirected, but I am also interested in more general cases.

Based on this network I would like to perform a community detection to group "similar" nodes together. I know there is a whole bunch of community detection methods in R igraph. See for example here or here.

But none of these cases deals with negative weights.

Is there an implementation in igraph (or in some other R package) which can deal with directed networks which have negative weights? Any hints are very appreciated.

user436994
  • 601
  • 5
  • 15
  • Add 1 to the weights and have them go from 0 to 2 ? – G5W May 14 '18 at 16:29
  • 1
    Well, I wonder if this would bias the community detection algorithm. A weight of -1 means strongly anticorrelated nodes whereas by adding 1 to the weights this would be zero - i.e. no link between the nodes. – user436994 May 14 '18 at 16:38
  • I think you want to use the `abs` of your weights or square them (i.e. use R^2). To me, a weight is a measure of strength, not direction. That is: two nodes connected by a weight of -1 is of equal importance as a weight of 1 because both represent a 1-to-1 relationship between the two variables albeit in different directions. – emilliman5 May 14 '18 at 18:14
  • I was thinking more of something like this: https://journals.aps.org/pre/abstract/10.1103/PhysRevE.80.036115 There is a Python implementation which can deal with this sort of problem: https://github.com/vtraag/louvain-igraph But I couldn't find somehting similar for R – user436994 May 15 '18 at 07:28
  • 1
    `cluster_spinglass` handles negative weights – emilliman5 May 15 '18 at 18:50

1 Answers1

0

Not 100 % sure, if it violates any assumptions, but as a workaround I set all negative edge weights to zero before calculating Louvain community detection with igraph in R. At least, they are never included in community relationships.

E(g)$width <- ifelse(E(g)$width < 0, 0, E(g)$width)
g.louv <- cluster_louvain(g, weights = E(g)$width)

Note: this applies only to undirected graphs (I overlooked this detail of the question, sorry)

bathyscapher
  • 1,615
  • 1
  • 13
  • 18
  • as far as I know `cluster_louvain` in `igraph` does not handle directed weighted graphs. – desval Oct 19 '20 at 17:32
  • I mean, from the `cluster_louvain` manual of `igraph` 1.2.5: `weights: Optional positive weight vector. If the graph has a weight edge attribute, then this is used by default. Supply NA here if the graph has a weight edge attribute, but you want to ignore it. Larger edge weights correspond to stronger connections.` [Also, the algorithm was developed for weighted networks](https://iopscience.iop.org/article/10.1088/1742-5468/2008/10/P10008). – bathyscapher Oct 20 '20 at 18:20
  • 1
    weights work (obviously). It doesn't work on weighted directed networks (would need to change the definition of modularity). Maybe there is something out there, but it hasnt been implemented in igraph r, yet. – desval Oct 21 '20 at 06:13
  • Very true indeed! I overlooked this, sorry. Do I better delete my answer then? ... – bathyscapher Oct 21 '20 at 09:59
  • I would leave it, maybe somebody will find it useful – desval Oct 22 '20 at 07:07