Network density and average path length
The first graph level metric you will explore is the density of a graph. This is essentially the proportion of all potential edges between vertices that actually exist in the network graph. It is an indicator of how well connected the vertices of the graph are.
Another measure of how interconnected a network is average path length. This is calculated by determining the mean of the lengths of the shortest paths between all pairs of vertices in the network. The longest path length between any pair of vertices is called the diameter of the network graph. You will calculate the diameter and average path length of the original graph g
.
This is a part of the course
“Network Analysis in R”
Exercise instructions
- Using the function
edge_density()
calculate the density of the graphg
and assign this value to the vectorgd
. - Use
diameter()
to calculate the diameter of the original graphg
. - Assign the average path length of
g
tog.apl
with the functionmean_distance()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(igraph)
# Get density of a graph
gd <- ___(g)
# Get the diameter of the graph g
___(g, directed = FALSE)
# Get the average path length of the graph g
g.apl <- ___(g, directed = FALSE)
g.apl