Assortativity
In this exercise you will determine the assortativity()
of the second friendship network from the first chapter. This is a measure of how preferentially attached vertices are to other vertices with identical attributes. You will also determine the degree assortativity which determines how preferentially attached are vertices to other vertices of a similar degree.
This exercise is part of the course
Network Analysis in R
Exercise instructions
- Make an exploratory plot of the friendship network object
g1
usingplot()
. - Convert the
gender
attribute of each vertex to a vector of numbers calledvalues
by factorizing and then usingas.numeric()
. - Calculate the assortativity based on gender by using the function
assortativity()
. The first argument should be the graph objectg1
. The second argument are thevalues
. - Calculate the degree assortativity of the network using
assortativity.degree()
. The first argument should be the graph object.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Plot the network
___(g1)
# Convert the gender attribute into a numeric value
values <- as.numeric(factor(V(___)$___))
# Calculate the assortativity of the network based on gender
___(g1, ___)
# Calculate the assortativity degree of the network
___(___, directed = FALSE)