[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[igraph] Calculating average shortest path
From: |
Claudia Muller-Birn |
Subject: |
[igraph] Calculating average shortest path |
Date: |
Sat, 5 Mar 2011 23:53:14 +0100 |
Dear all,
I have a rather simple question regarding calculating the average shortest path
length. There are actually to ways calculating it and I am wondering why I get
two different results. Here is my toy example:
> g1 <- graph( c( 0,1, 1,2, 2,1, 2,3 ), directed=FALSE )
> g2 <- graph( c( 0,1, 1,2, 2,1, 2,3 ), directed=TRUE )
First possibility to calculate the average shortest path (or is it just one
path???)
> average.path.length(g1, directed=FALSE)
[1] 1.666667
> average.path.length(g2, directed=TRUE)
[1] 1.571429
Second possibility would be by just calling the mean
> sp1 <- shortest.paths(g1)
> mean(sp1,na.rm=TRUE)
[1] 1.25
> sp2 <- shortest.paths(g2, v=V(g2), mode='out')
> sp2[is.infinite(sp2)]<-NA
> mean(sp2,na.rm=TRUE)
[1] 1
In my opinion, the second way to calculate the average shortest paths makes
much more sense but then I am wondering about the meaning and calculation of
the first possibility based on average.path.length. How is the latter function
implemented or do I miss some settings?
Thank you very much for any help or idea.
Best,
Claudia
- [igraph] Calculating average shortest path,
Claudia Muller-Birn <=