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.
Bu egzersiz
Network Analysis in R
kursunun bir parçasıdırEgzersiz talimatları
- Use
assortativity()to calculate the assortativity of the graph objectg1based on gender using the objectvaluescalculated in the previous exercise, and assign this to the objectobserved.assortativity. - Inside the for loop calculate the assortativity of the network
g1usingassortativity()while randomly permuting the objectvalueseach time withsample(). - Plot the distribution of assortativity values from this permutation procedure using
hist()and add a red vertical line for the originalg1network observed assortativity value that is stored inobserved.assortativity.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# 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)