Random graphs
Generating random graphs is an important method for investigating how likely or unlikely other network metrics are likely to occur given certain properties of the original graph. The simplest random graph is one that has the same number of vertices as your original graph and approximately the same density as the original graph. Here you will create one random graph that is based on the original Forrest Gump Network.
Cet exercice fait partie du cours
Network Analysis in R
Instructions
- Generate a random graph using the function
erdos.renyi.game()
. The first argumentn
should be the number of nodes of the graphg
which can be calculated usinggorder()
, the second argumentp.or.m
should be the density of the graphg
which you previously stored as the objectgd
. The final argument is set astype='gnp'
to tell the function that you are using the density of the graph to generate a random graph. Store this new graph as the vectorg.random
. - Get the density of the random graph
g.random
. You will notice if you generate a random graph a few times that this value will slightly vary but be approximately equal to the density of your original graphg
from the previous exercise stored in the objectgd
. - Calculate the average path length of the random graph
g.random
.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
library(igraph)
# Create one random graph with the same number of nodes and edges as g
g.random <- ___(n = ___, p.or.m = ___, type = "gnp")
g.random
plot(g.random)
# Get density of new random graph `g.random`
___(___)
# Get the average path length of the random graph g.random
___(___, directed = FALSE)