Hi,

I want to implement community detection in R. I used the following functions and got these errors:

```
d1<-cluster_edge_betweenness(g2,directed='TRUE')
Error in cluster_edge_betweenness(g2, directed = "TRUE") :
At community.c:455 : weights must be strictly positive, Invalid value
```

```
d1<-cluster_leading_eigen(g2)
Modularity is implemented for undirected graphs only.
Error in cluster_leading_eigen(g2) :
At community.c:933 : negative weight in weight vector, Invalid value
Warning message:
In cluster_leading_eigen(g2) :
At community.c:1597 :This method was developed for undirected graphs
```

```
d1<-cluster_infomap(g2)
Modularity is implemented for undirected graphs only.
Error in modularity.igraph(graph, res$membership, weights = e.weights) :
At community.c:933 : negative weight in weight vector, Invalid value
```

Does anyone know how I can solve it?

I also tried to compute modularity in python, but but it says that ‘Modularity is implemented for undirected graphs only.’

Thank you

You seem to have negative edge weights. I wonder why, and what the interpretation of those edge weights is. Can you convert them to positive ones without breaking the interpretation?

There is an implementation for dealing with negative weights (using an adaptation of modularity), see https://www.rdocumentation.org/packages/igraph/versions/1.2.5/topics/cluster_spinglass. The other errors concern the fact that you have a directed network, you might be able to convert that to an undirected network?

How can I convert the edges to positive ones?

This is a matter of interpretation of your data. You need to think about:

- What those numbers mean in the first place?
- Does community detection make sense with these weights?
- Is there a reason to believe that this network has a clear community structure? Given that you have negative weights, I’d wonder if community detection is really what you need here?
- How does the interpretation of the numbers change if you perform a given transformation? Would it affect their meaning for the purpose of community detection?

Ideally, you can connect the numbers to some physical mechanism that could potentially take place on your network. That could then serve as a basis of interpretation.

To be sure, the negative weights may have a reasonable interpretation (e.g. negative weights may indicate animosity, while positive weights indicate friendship). Such networks with negative links (or negative weights) are often called “signed networks”. This is quite common is various social networks (and also some other types of networks), and is often treated under the heading of “social balance” or “structural balance”.

One analysis that is done on such networks is to group nodes such that positive links are within groups, while negative links are between groups. This objective is not unlike community detection, and a possible method for that is implemented in the `spinglass`

method I referred to earlier.

For more background reading, I have written a short chapter about partitioning signed networks https://arxiv.org/abs/1803.02082.

1 Like