Network Analysis Part 3 Exercises

October 20, 2016

(This article was first published on R-exercises, and kindly contributed to R-bloggers)


This is the third set of exercises on networks in which we practice the functions for graph structure, using package igraph. The first and second part are available here:

Part 1
Part 2

If you don’t have package already installed, install it using the following code:


and load it into the session using the following code:


before proceeding. You can find more info about the package and graphs in general here

Answers to the exercises are available here.

If you have different solution, feel free to post it.

A number of employees in a factory was interview on question: “Do you like to work with your co-worker?”. Possible answers are 1 for yes and 0 for no. Each employee gave answer for each other employee thus creating adjacency matrix. You can download data set from here.

Exercise 1

Load the data and create un-directed graph from adjacency matrix. Name nodes as letters A to Y. Set node color to orange and shape to square. Set edge’s color to blue and arrow size to 0.2. Plot the graph.

Exercise 2

Find the largest cliques in the group.

Exercise 3

How many maximal cliques are there?

Exercise 4

Calculate the network cohesion.

Exercise 5

Find the clusters based on betweenness.

Exercise 6

Find the components of a graph.

Exercise 7

Find the loop edges.

Exercise 8

How many triangles are there in the graph? In how many of them is vertex S included?

Exercise 9

What is the global clustering coefficient of this network? Can we say that clustering is statistically significant for this network.Tip: in order to determine if clustering coefficient is significant, it should be much larger than the random network with the same number of vertices and edges.

Exercise 10

Create and draw the following types of networks:

  • Random with 10 nodes and probability of an edge of 0.4 (Erdos-Renyi random graph)
  • Full un-directed graph with 15 nodes
  • Star network with 20 nodes
  • Directed ring network with 15 nodes and mutual edges

To leave a comment for the author, please follow the link and comment on their blog: R-exercises. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)