Average distance in a disconnected graph

139 Views Asked by At

I can't seem to figure out the formula behind the function mean_distance from igraph when unconnected=TRUE.

If the output for distances(n) is:

  0   1   1   2 Inf Inf
  1   0   1   1 Inf Inf
  1   1   0   1 Inf Inf
  2   1   1   0 Inf Inf
Inf Inf Inf Inf   0   1
Inf Inf Inf Inf   1   0

Then the result for mean_distance(n, unconnected=TRUE) is 1.142857.

I have read the igraph documentation, but I can't reach the value above doing the math by myself without using the function mean_distance.

Can someone tell me the mathematic formula behind this function?

1

There are 1 best solutions below

0
On

It appears to be returning the average of all finite distances between different vertices. In other words, the average of all the values in your table that are neither 0 nor Inf. There are $14$ of these, of which $12$ are 1 and $2$ are 2, so the average is $16/14=1.\dot 14285\dot 7$.