Using randomizations to assess assortativity
In this exercise you will determine how likely the observed assortativity in the friendship network is given the genders of vertices by performing a randomization procedure. You will randomly permute the gender of vertices in the network 1000 times and recalculate the assortativity for each random network.
Este ejercicio forma parte del curso
Network Analysis in R
Instrucciones del ejercicio
- Use
assortativity()
to calculate the assortativity of the graph objectg1
based on gender using the objectvalues
calculated in the previous exercise, and assign this to the objectobserved.assortativity
. - Inside the for loop calculate the assortativity of the network
g1
usingassortativity()
while randomly permuting the objectvalues
each time withsample()
. - Plot the distribution of assortativity values from this permutation procedure using
hist()
and add a red vertical line for the originalg1
network observed assortativity value that is stored inobserved.assortativity
.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Calculate the observed assortativity
observed.assortativity <- ___(g1, values)
# Calculate the assortativity of the network randomizing the gender attribute 1000 times
results <- vector('list', 1000)
for(i in 1:1000){
results[[i]] <- ___(g1, sample(___))
}
# Plot the distribution of assortativity values and add a red vertical line at the original observed value
___(unlist(results))
abline(v = ___, col = "red", lty = 3, lwd=2)