Formula: \(L = (1/|R|)\sum_{(i,j) \in R} d(i,j)\) over the ordered
pairs with \(i \ne j\) that are actually connected, and
\(L_{harm}^{-1} = (1/(n(n-1)))\sum_{i \ne j} 1/d(i,j)\) with
\(1/d = 0\) for unreachable pairs. The arithmetic mean diverges
the moment the graph is disconnected, so unreachable pairs are
dropped from \(L\) and counted in reachable rather than
imputed; the harmonic mean is the standard repair and is always
finite. Distances come from breadth-first search, so the graph is
unweighted – a non-zero entry means an edge, not a length.
References
Newman (2010), Networks: An Introduction, OUP, sec. 7.6, and the harmonic-mean repair for disconnected graphs. The book is not in the local corpus and is not fetchable, so this is the standard published form rather than a quoted equation; the two conventions that are genuinely in dispute – self-pairs and unreachable pairs – are stated above and reported separately.
Examples
Avgpathlen(matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0), 3, 3, byrow = TRUE))
#> $estimate
#> [1] 1.333333
#>
#> $harmonic
#> [1] 1.2
#>
#> $diameter
#> [1] 2
#>
#> $reachable
#> [1] 6
#>
#> $pairs
#> [1] 6
#>
#> $n
#> [1] 3
#>
#> $method
#> [1] "Mean geodesic distance"
#>
#> attr(,"class")
#> [1] "morie_rich_result" "list"
