Get startedGet started for free

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

View Course

Exercise instructions

  • Make an exploratory plot of the friendship network object g1 using plot().
  • Convert the gender attribute of each vertex to a vector of numbers called values by factorizing and then using as.numeric().
  • Calculate the assortativity based on gender by using the function assortativity(). The first argument should be the graph object g1. The second argument are the values.
  • 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)

Edit and Run Code