Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R igraph graph density, diameter, eccentricity and shortest path

Tags:

r

igraph

I hope someone can help me out.

I have an undirected graph g with n=2071 nodes and m=9023 edges. I calculated the graph density in R using the igraph package and got the following:

> graph.density(g,loop=FALSE)
[1] 0.00210475

However, using the formula for graph density, i.e. density = mean degree / (n-1), I got the following:

> mean(degree(g))/(vcount(g)-1)
[1] 0.0042095

Why does graph.density() give me a different (is it wrong?) answer?

Another question, doesn't the maximum eccentricity = diameter = maximum shortest path of the graph? Or am I confusing the concepts? Calculating in R using the igraph package, I got the following:

> max(shortest.paths(g,mode="all"))
[1] 17
> diameter(g,directed=FALSE,unconnected=FALSE,weights=NULL)
[1] 17
> max(eccentricity(g,mode="all"))
[1] 8

I used Gephi to double check and I got the diameter=8. Why is there a disparity between the values?

Also, I found an almost similar question asked before (igraph radius and diameter), but it does not quite ask/answer what I want. It says that the bug has been fixed.

like image 979
Melody Tan Avatar asked Dec 11 '25 19:12

Melody Tan


1 Answers

The diameter calculation in igraph considers the edge weights while performing the calculation, so in order to make the calculated diameter same in both igraph and Gephi we need to set weights parameter to 'NA' in igraph.

diameter(graph_data, weights = NA)
like image 114
Ritika Sharma Avatar answered Dec 13 '25 09:12

Ritika Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!