Triangles and transitivity
Another important measure of local connectivity in a network graph involves investigating triangles (also known as triads). In this exercise you will find all closed triangles that exist in a network. This means that an edge exists between three given vertices. You can then calculate the transitivity of the network. This is equivalent to the proportion of all possible triangles in the network that are closed. You will also learn how to identify the number of closed triangles that any given vertex is a part of and its local transitivity - that is, the proportion of closed triangles that the vertex is a part of given the theoretical number of triangles it could be a part of.
This exercise is part of the course
Network Analysis in R
Exercise instructions
- Show a matrix of all possible triangles in the Forrest Gump network
g
using the functiontriangles()
. - Using the function
count_triangles()
, find how many triangles that the vertex"BUBBA"
is a part of. Thevids
argument refers to the id of the vertex. - Calculate the global transitivity of the network
g
usingtransitivity()
. - Find the local transitivity of vertex
"BUBBA"
also using the functiontransitivity()
. The type is defined aslocal
to indicate that you are calculating a local rather than global transitivity.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(igraph)
# Show all triangles in the network.
matrix(___(g), nrow = 3)
# Count the number of triangles that vertex "BUBBA" is in.
___(g, vids='___')
# Calculate the global transitivity of the network.
g.tr <- ___(g)
g.tr
# Calculate the local transitivity for vertex BUBBA.
___(g, vids='___', type = "local")