Distances to and from a vertex
v_distance(
x,
mode = c("all", "out", "in"),
weights = NULL,
count_unnconnected = FALSE
)
data frame
For each vertex, this function returns the average distance to all other vertices, the standard deviation of the distances, the maximum distance, the median distance, and the smmed distances.
The distances are determined either following the direction of the edges ( "out" or "in")βin case of a directed network, or irrespective of edge direction.
Distances can be weighted against an edge attribute.
When the graph is not connected, it is not obvious how to include the distances
to/from unconnected vertices. If count_unnconnected
is TRUE
, the
distances will count as infinite and most of the statistics will hence be
infinite too. If count_unnconnected
is TRUE
, the paths to and from
unconnected vertices are not included. Isolates will then have zero and NA
scores, obviously.
data("florentine", package = "snafun")
g <- florentine$flobusiness
v_distance(g, mode = "all", count_unnconnected = FALSE)
#> Warning: The graph is not fully strongly connected, interpret result with prudence.
#> average median stdev max sum
#> Acciaiuoli 0.00 0 NA 0 0
#> Albizzi 0.00 0 NA 0 0
#> Barbadori 1.06 2 0.82 3 17
#> Bischeri 1.56 2 1.42 4 25
#> Castellani 1.25 2 0.98 3 20
#> Ginori 1.38 2 1.10 4 22
#> Guadagni 2.00 3 1.81 5 32
#> Lamberteschi 1.50 2 1.47 4 24
#> Medici 1.19 1 1.19 4 19
#> Pazzi 1.75 2 1.44 5 28
#> Peruzzi 1.19 2 1.01 3 19
#> Pucci 0.00 0 NA 0 0
#> Ridolfi 0.00 0 NA 0 0
#> Salviati 1.75 2 1.44 5 28
#> Strozzi 0.00 0 NA 0 0
#> Tornabuoni 1.75 2 1.44 5 28
v_distance(g, mode = "all", count_unnconnected = TRUE)
#> Warning: The graph is not fully strongly connected, interpret result with prudence.
#> average median stdev max sum
#> Acciaiuoli Inf Inf NaN Inf Inf
#> Albizzi Inf Inf NaN Inf Inf
#> Barbadori Inf 2.0 NaN Inf Inf
#> Bischeri Inf 3.5 NaN Inf Inf
#> Castellani Inf 2.5 NaN Inf Inf
#> Ginori Inf 2.5 NaN Inf Inf
#> Guadagni Inf 4.5 NaN Inf Inf
#> Lamberteschi Inf 3.5 NaN Inf Inf
#> Medici Inf 2.5 NaN Inf Inf
#> Pazzi Inf 3.5 NaN Inf Inf
#> Peruzzi Inf 2.5 NaN Inf Inf
#> Pucci Inf Inf NaN Inf Inf
#> Ridolfi Inf Inf NaN Inf Inf
#> Salviati Inf 3.5 NaN Inf Inf
#> Strozzi Inf Inf NaN Inf Inf
#> Tornabuoni Inf 3.5 NaN Inf Inf
v_distance(g, mode = "in", count_unnconnected = FALSE)
#> Warning: The graph is not fully weakly connected, interpret result with prudence.
#> average median stdev max sum
#> Acciaiuoli 0.00 0 NA 0 0
#> Albizzi 0.00 0 NA 0 0
#> Barbadori 1.06 2 0.82 3 17
#> Bischeri 1.56 2 1.42 4 25
#> Castellani 1.25 2 0.98 3 20
#> Ginori 1.38 2 1.10 4 22
#> Guadagni 2.00 3 1.81 5 32
#> Lamberteschi 1.50 2 1.47 4 24
#> Medici 1.19 1 1.19 4 19
#> Pazzi 1.75 2 1.44 5 28
#> Peruzzi 1.19 2 1.01 3 19
#> Pucci 0.00 0 NA 0 0
#> Ridolfi 0.00 0 NA 0 0
#> Salviati 1.75 2 1.44 5 28
#> Strozzi 0.00 0 NA 0 0
#> Tornabuoni 1.75 2 1.44 5 28
v_distance(g, mode = "out", count_unnconnected = FALSE)
#> Warning: The graph is not fully weakly connected, interpret result with prudence.
#> average median stdev max sum
#> Acciaiuoli 0.00 0 NA 0 0
#> Albizzi 0.00 0 NA 0 0
#> Barbadori 1.06 2 0.82 3 17
#> Bischeri 1.56 2 1.42 4 25
#> Castellani 1.25 2 0.98 3 20
#> Ginori 1.38 2 1.10 4 22
#> Guadagni 2.00 3 1.81 5 32
#> Lamberteschi 1.50 2 1.47 4 24
#> Medici 1.19 1 1.19 4 19
#> Pazzi 1.75 2 1.44 5 28
#> Peruzzi 1.19 2 1.01 3 19
#> Pucci 0.00 0 NA 0 0
#> Ridolfi 0.00 0 NA 0 0
#> Salviati 1.75 2 1.44 5 28
#> Strozzi 0.00 0 NA 0 0
#> Tornabuoni 1.75 2 1.44 5 28
v_distance(snafun::to_network(g), mode = "all", count_unnconnected = FALSE)
#> Warning: The graph is not fully strongly connected, interpret result with prudence.
#> average median stdev max sum
#> Acciaiuoli 0.00 0 NA 0 0
#> Albizzi 0.00 0 NA 0 0
#> Barbadori 1.06 2 0.82 3 17
#> Bischeri 1.56 2 1.42 4 25
#> Castellani 1.25 2 0.98 3 20
#> Ginori 1.38 2 1.10 4 22
#> Guadagni 2.00 3 1.81 5 32
#> Lamberteschi 1.50 2 1.47 4 24
#> Medici 1.19 1 1.19 4 19
#> Pazzi 1.75 2 1.44 5 28
#> Peruzzi 1.19 2 1.01 3 19
#> Pucci 0.00 0 NA 0 0
#> Ridolfi 0.00 0 NA 0 0
#> Salviati 1.75 2 1.44 5 28
#> Strozzi 0.00 0 NA 0 0
#> Tornabuoni 1.75 2 1.44 5 28
v_distance(snafun::to_network(g), mode = "all", count_unnconnected = TRUE)
#> Warning: The graph is not fully strongly connected, interpret result with prudence.
#> average median stdev max sum
#> Acciaiuoli Inf Inf NaN Inf Inf
#> Albizzi Inf Inf NaN Inf Inf
#> Barbadori Inf 2.0 NaN Inf Inf
#> Bischeri Inf 3.5 NaN Inf Inf
#> Castellani Inf 2.5 NaN Inf Inf
#> Ginori Inf 2.5 NaN Inf Inf
#> Guadagni Inf 4.5 NaN Inf Inf
#> Lamberteschi Inf 3.5 NaN Inf Inf
#> Medici Inf 2.5 NaN Inf Inf
#> Pazzi Inf 3.5 NaN Inf Inf
#> Peruzzi Inf 2.5 NaN Inf Inf
#> Pucci Inf Inf NaN Inf Inf
#> Ridolfi Inf Inf NaN Inf Inf
#> Salviati Inf 3.5 NaN Inf Inf
#> Strozzi Inf Inf NaN Inf Inf
#> Tornabuoni Inf 3.5 NaN Inf Inf
v_distance(snafun::to_network(g), mode = "in", count_unnconnected = FALSE)
#> Warning: The graph is not fully weakly connected, interpret result with prudence.
#> average median stdev max sum
#> Acciaiuoli 0.00 0 NA 0 0
#> Albizzi 0.00 0 NA 0 0
#> Barbadori 1.06 2 0.82 3 17
#> Bischeri 1.56 2 1.42 4 25
#> Castellani 1.25 2 0.98 3 20
#> Ginori 1.38 2 1.10 4 22
#> Guadagni 2.00 3 1.81 5 32
#> Lamberteschi 1.50 2 1.47 4 24
#> Medici 1.19 1 1.19 4 19
#> Pazzi 1.75 2 1.44 5 28
#> Peruzzi 1.19 2 1.01 3 19
#> Pucci 0.00 0 NA 0 0
#> Ridolfi 0.00 0 NA 0 0
#> Salviati 1.75 2 1.44 5 28
#> Strozzi 0.00 0 NA 0 0
#> Tornabuoni 1.75 2 1.44 5 28
v_distance(snafun::to_network(g), mode = "out", count_unnconnected = FALSE)
#> Warning: The graph is not fully weakly connected, interpret result with prudence.
#> average median stdev max sum
#> Acciaiuoli 0.00 0 NA 0 0
#> Albizzi 0.00 0 NA 0 0
#> Barbadori 1.06 2 0.82 3 17
#> Bischeri 1.56 2 1.42 4 25
#> Castellani 1.25 2 0.98 3 20
#> Ginori 1.38 2 1.10 4 22
#> Guadagni 2.00 3 1.81 5 32
#> Lamberteschi 1.50 2 1.47 4 24
#> Medici 1.19 1 1.19 4 19
#> Pazzi 1.75 2 1.44 5 28
#> Peruzzi 1.19 2 1.01 3 19
#> Pucci 0.00 0 NA 0 0
#> Ridolfi 0.00 0 NA 0 0
#> Salviati 1.75 2 1.44 5 28
#> Strozzi 0.00 0 NA 0 0
#> Tornabuoni 1.75 2 1.44 5 28
data(emon, package = "network")
g_n <- emon$LakePomona
v_distance(g_n, mode = "all")
#> Warning: The graph is not fully strongly connected, interpret result with prudence.
#> average median stdev max sum
#> Osage.County.Sheriffs.Department 0.95 1.0 0.22 1 19
#> Osage.County.Civil.Defense.Office 1.30 1.0 0.57 2 26
#> Osage.Country.Coroners.Office 1.35 1.0 0.59 2 27
#> Osage.County.Attorneys.Office 1.45 1.5 0.60 2 29
#> Kansas.State.Highway.Patrol 0.95 1.0 0.22 1 19
#> Kansas.State.Parks.and.Resources.Authority 1.20 1.0 0.52 2 24
#> Kansas.State.Game.and.Fish.Commission 1.15 1.0 0.49 2 23
#> Kansas.State.Department.of.Transportation 1.70 2.0 0.57 2 34
#> US.Army.Corps.of.Engineers 1.30 1.0 0.57 2 26
#> US.Army.Reserve 1.60 2.0 0.60 2 32
#> Crable.Ambulance 1.45 1.5 0.60 2 29
#> Franklin.County.Ambulance 1.50 2.0 0.61 2 30
#> Lees.Summit.Underwater.Rescue.Team..Missouri. 1.65 2.0 0.59 2 33
#> Shawnee.County.CD.Underwater.Rescue.Team 1.20 1.0 0.52 2 24
#> Burlingame.Police.Department 1.10 1.0 0.45 2 22
#> Lyndon.Police.Department 1.50 2.0 0.61 2 30
#> American.Red.Cross 1.25 1.0 0.55 2 25
#> Topeka.Fire.Department.Rescue.No.1 1.65 2.0 0.59 2 33
#> Carbondale.Fire.Department 1.55 2.0 0.60 2 31
#> Topeka.Radiator.and.Body.Works 1.60 2.0 0.60 2 32
v_distance(g_n, mode = "in")
#> average median stdev max sum
#> Osage.County.Sheriffs.Department 0.95 1.0 0.22 1 19
#> Osage.County.Civil.Defense.Office 1.60 2.0 0.60 2 32
#> Osage.Country.Coroners.Office 1.35 1.0 0.59 2 27
#> Osage.County.Attorneys.Office 1.65 2.0 0.59 2 33
#> Kansas.State.Highway.Patrol 0.95 1.0 0.22 1 19
#> Kansas.State.Parks.and.Resources.Authority 1.25 1.0 0.55 2 25
#> Kansas.State.Game.and.Fish.Commission 1.25 1.0 0.55 2 25
#> Kansas.State.Department.of.Transportation 0.00 0.0 NA 0 0
#> US.Army.Corps.of.Engineers 1.35 1.0 0.59 2 27
#> US.Army.Reserve 1.80 2.0 0.70 3 36
#> Crable.Ambulance 1.55 2.0 0.60 2 31
#> Franklin.County.Ambulance 1.65 2.0 0.59 2 33
#> Lees.Summit.Underwater.Rescue.Team..Missouri. 1.70 2.0 0.57 2 34
#> Shawnee.County.CD.Underwater.Rescue.Team 1.55 2.0 0.60 2 31
#> Burlingame.Police.Department 1.80 2.0 0.52 2 36
#> Lyndon.Police.Department 1.60 2.0 0.60 2 32
#> American.Red.Cross 1.40 1.0 0.60 2 28
#> Topeka.Fire.Department.Rescue.No.1 2.30 2.5 0.86 3 46
#> Carbondale.Fire.Department 0.00 0.0 NA 0 0
#> Topeka.Radiator.and.Body.Works 1.70 2.0 0.57 2 34
v_distance(g_n, mode = "out")
#> average median stdev max sum
#> Osage.County.Sheriffs.Department 1.15 1.0 0.57 2 23
#> Osage.County.Civil.Defense.Office 1.25 1.0 0.61 2 25
#> Osage.Country.Coroners.Office 1.40 2.0 0.70 3 28
#> Osage.County.Attorneys.Office 1.30 1.5 0.62 2 26
#> Kansas.State.Highway.Patrol 1.10 1.0 0.55 2 22
#> Kansas.State.Parks.and.Resources.Authority 1.25 1.0 0.61 2 25
#> Kansas.State.Game.and.Fish.Commission 1.35 1.5 0.71 3 27
#> Kansas.State.Department.of.Transportation 1.65 2.0 0.65 3 33
#> US.Army.Corps.of.Engineers 1.40 2.0 0.70 3 28
#> US.Army.Reserve 1.65 2.0 0.62 3 33
#> Crable.Ambulance 1.40 2.0 0.70 3 28
#> Franklin.County.Ambulance 1.55 2.0 0.67 3 31
#> Lees.Summit.Underwater.Rescue.Team..Missouri. 1.70 2.0 0.68 3 34
#> Shawnee.County.CD.Underwater.Rescue.Team 1.15 1.0 0.57 2 23
#> Burlingame.Police.Department 0.90 1.0 0.34 2 18
#> Lyndon.Police.Department 1.45 2.0 0.70 3 29
#> American.Red.Cross 1.25 1.0 0.61 2 25
#> Topeka.Fire.Department.Rescue.No.1 1.55 2.0 0.67 3 31
#> Carbondale.Fire.Department 1.50 2.0 0.69 3 30
#> Topeka.Radiator.and.Body.Works 1.45 2.0 0.61 2 29
g_i <- snafun::to_igraph(g_n)
v_distance(g_i, mode = "all")
#> Warning: The graph is not fully strongly connected, interpret result with prudence.
#> average median stdev max sum
#> Osage.County.Sheriffs.Department 0.95 1.0 0.22 1 19
#> Osage.County.Civil.Defense.Office 1.30 1.0 0.57 2 26
#> Osage.Country.Coroners.Office 1.35 1.0 0.59 2 27
#> Osage.County.Attorneys.Office 1.45 1.5 0.60 2 29
#> Kansas.State.Highway.Patrol 0.95 1.0 0.22 1 19
#> Kansas.State.Parks.and.Resources.Authority 1.20 1.0 0.52 2 24
#> Kansas.State.Game.and.Fish.Commission 1.15 1.0 0.49 2 23
#> Kansas.State.Department.of.Transportation 1.70 2.0 0.57 2 34
#> US.Army.Corps.of.Engineers 1.30 1.0 0.57 2 26
#> US.Army.Reserve 1.60 2.0 0.60 2 32
#> Crable.Ambulance 1.45 1.5 0.60 2 29
#> Franklin.County.Ambulance 1.50 2.0 0.61 2 30
#> Lees.Summit.Underwater.Rescue.Team..Missouri. 1.65 2.0 0.59 2 33
#> Shawnee.County.CD.Underwater.Rescue.Team 1.20 1.0 0.52 2 24
#> Burlingame.Police.Department 1.10 1.0 0.45 2 22
#> Lyndon.Police.Department 1.50 2.0 0.61 2 30
#> American.Red.Cross 1.25 1.0 0.55 2 25
#> Topeka.Fire.Department.Rescue.No.1 1.65 2.0 0.59 2 33
#> Carbondale.Fire.Department 1.55 2.0 0.60 2 31
#> Topeka.Radiator.and.Body.Works 1.60 2.0 0.60 2 32
v_distance(g_i, mode = "in")
#> average median stdev max sum
#> Osage.County.Sheriffs.Department 0.95 1.0 0.22 1 19
#> Osage.County.Civil.Defense.Office 1.60 2.0 0.60 2 32
#> Osage.Country.Coroners.Office 1.35 1.0 0.59 2 27
#> Osage.County.Attorneys.Office 1.65 2.0 0.59 2 33
#> Kansas.State.Highway.Patrol 0.95 1.0 0.22 1 19
#> Kansas.State.Parks.and.Resources.Authority 1.25 1.0 0.55 2 25
#> Kansas.State.Game.and.Fish.Commission 1.25 1.0 0.55 2 25
#> Kansas.State.Department.of.Transportation 0.00 0.0 NA 0 0
#> US.Army.Corps.of.Engineers 1.35 1.0 0.59 2 27
#> US.Army.Reserve 1.80 2.0 0.70 3 36
#> Crable.Ambulance 1.55 2.0 0.60 2 31
#> Franklin.County.Ambulance 1.65 2.0 0.59 2 33
#> Lees.Summit.Underwater.Rescue.Team..Missouri. 1.70 2.0 0.57 2 34
#> Shawnee.County.CD.Underwater.Rescue.Team 1.55 2.0 0.60 2 31
#> Burlingame.Police.Department 1.80 2.0 0.52 2 36
#> Lyndon.Police.Department 1.60 2.0 0.60 2 32
#> American.Red.Cross 1.40 1.0 0.60 2 28
#> Topeka.Fire.Department.Rescue.No.1 2.30 2.5 0.86 3 46
#> Carbondale.Fire.Department 0.00 0.0 NA 0 0
#> Topeka.Radiator.and.Body.Works 1.70 2.0 0.57 2 34
v_distance(g_i, mode = "out")
#> average median stdev max sum
#> Osage.County.Sheriffs.Department 1.15 1.0 0.57 2 23
#> Osage.County.Civil.Defense.Office 1.25 1.0 0.61 2 25
#> Osage.Country.Coroners.Office 1.40 2.0 0.70 3 28
#> Osage.County.Attorneys.Office 1.30 1.5 0.62 2 26
#> Kansas.State.Highway.Patrol 1.10 1.0 0.55 2 22
#> Kansas.State.Parks.and.Resources.Authority 1.25 1.0 0.61 2 25
#> Kansas.State.Game.and.Fish.Commission 1.35 1.5 0.71 3 27
#> Kansas.State.Department.of.Transportation 1.65 2.0 0.65 3 33
#> US.Army.Corps.of.Engineers 1.40 2.0 0.70 3 28
#> US.Army.Reserve 1.65 2.0 0.62 3 33
#> Crable.Ambulance 1.40 2.0 0.70 3 28
#> Franklin.County.Ambulance 1.55 2.0 0.67 3 31
#> Lees.Summit.Underwater.Rescue.Team..Missouri. 1.70 2.0 0.68 3 34
#> Shawnee.County.CD.Underwater.Rescue.Team 1.15 1.0 0.57 2 23
#> Burlingame.Police.Department 0.90 1.0 0.34 2 18
#> Lyndon.Police.Department 1.45 2.0 0.70 3 29
#> American.Red.Cross 1.25 1.0 0.61 2 25
#> Topeka.Fire.Department.Rescue.No.1 1.55 2.0 0.67 3 31
#> Carbondale.Fire.Department 1.50 2.0 0.69 3 30
#> Topeka.Radiator.and.Body.Works 1.45 2.0 0.61 2 29