Network Analysis in R
James Curley
Associate Professor, University of Texas at Austin
erdos.renyi.game(n = gorder(g), p.or.m = edge_density(g), type = "gnp")
Generate 1000 random graphs based on the original network - e.g. with the same number of vertices and approximate density.
Calculate the average path length of the original network.
Calculate the average path length of the 1000 random networks.
Determine how many random networks have an average path length greater or less than the original network's average path length.
Generate 1000 random graphs:
gl <- vector('list',1000)
for(i in 1:1000){
gl[[i]] <- erdos.renyi.game(
n = gorder(g),
p.or.m = edge_density(g),
type = "gnp"
)
}
Calculate average path length of 1000 random graphs:
gl.apls <- unlist(
lapply(gl, mean_distance, directed = FALSE)
)
hist(gl.apls, breaks = 20)
abline(
v = mean_distance(
g, directed=FALSE
),
col = "red",
lty = 3,
lwd = 2
)
Network Analysis in R