LAB 4: Clusters, Factions and Cores

library('igraph')
## Warning: package 'igraph' was built under R version 3.4.3
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
library('cluster')
library('animation')
## Warning: package 'animation' was built under R version 3.4.3

Load the data

data(studentnets.M182, package = "NetData")

Reduce to non-zero edges and build a graph object

m182_full_nonzero_edges <- subset(m182_full_data_frame, (friend_tie > 0 | social_tie > 0 | task_tie > 0))
head(m182_full_nonzero_edges)
##    ego alter friend_tie social_tie task_tie
## 5    1     5          0       1.20     0.30
## 8    1     8          0       0.15     0.00
## 9    1     9          0       2.85     0.30
## 10   1    10          0       6.45     0.30
## 11   1    11          0       0.30     0.00
## 12   1    12          0       1.95     0.15
m182_full <- graph.data.frame(m182_full_nonzero_edges) 
summary(m182_full)
## IGRAPH ba62ba6 DN-- 16 144 -- 
## + attr: name (v/c), friend_tie (e/n), social_tie (e/n), task_tie
## | (e/n)

Create sub-graphs based on edge attributes

m182_friend <- delete.edges(m182_full, E(m182_full)[get.edge.attribute(m182_full,name = "friend_tie")==0])

m182_social <- delete.edges(m182_full, E(m182_full)[get.edge.attribute(m182_full,name = "social_tie")==0])
summary(m182_social)
## IGRAPH ba7b836 DN-- 16 129 -- 
## + attr: name (v/c), friend_tie (e/n), social_tie (e/n), task_tie
## | (e/n)
m182_task <- delete.edges(m182_full, E(m182_full)[get.edge.attribute(m182_full,name = "task_tie")==0])
summary(m182_task)
## IGRAPH ba83a7d DN-- 16 88 -- 
## + attr: name (v/c), friend_tie (e/n), social_tie (e/n), task_tie
## | (e/n)

Look at the plots for each sub-graph

friend_layout <- layout.fruchterman.reingold(m182_friend)
plot(m182_friend, layout=friend_layout, edge.arrow.size=.5)

social_layout <- layout.fruchterman.reingold(m182_social)
plot(m182_social, layout=social_layout, edge.arrow.size=.5)

task_layout <- layout.fruchterman.reingold(m182_task)
plot(m182_task, layout=task_layout, edge.arrow.size=.5)

Community detection

m182_friend_und <- as.undirected(m182_friend, mode='collapse')
m182_friend_no_iso <- delete.vertices(m182_friend_und, V(m182_friend_und)[degree(m182_friend_und)==0])
summary(m182_friend)
## IGRAPH ba72b75 DN-- 16 62 -- 
## + attr: name (v/c), friend_tie (e/n), social_tie (e/n), task_tie
## | (e/n)
summary(m182_friend_no_iso)
## IGRAPH bb3ea2f UN-- 14 42 -- 
## + attr: name (v/c)
friend_comm_wt <- walktrap.community(m182_friend_no_iso, steps=200,modularity=TRUE)
friend_comm_wt
## IGRAPH clustering walktrap, groups: 3, mod: 0.099
## + groups:
##   $`1`
##   [1] "2"  "8"  "13"
##   
##   $`2`
##   [1] "1"  "3"  "5"  "9"  "10" "12" "15"
##   
##   $`3`
##   [1] "6"  "7"  "11" "14"
## 
friend_comm_dend <- as.dendrogram(friend_comm_wt, use.modularity=TRUE)
plot(friend_comm_dend)

Question 2 - How many clusters would you select here and why?

According to me there are 5 clusters in this group. group 1: 2,8 group 2: 13 - singleton group 3: 6,7,11,14 group 4: 1,5,10,12 group 5: 1,9,15

I have clustered them according to the distance. For example: I see that points 2,8 are very far from 13 so I chose to put them in different groups. Whereas 3,9,15 were relatively closer therefore they formed a single cluster. As points 15,10,12 are closer to each other they form another cluster. Similarly points 6,7,11,14 form the last cluster.

friend_comm_eb <- edge.betweenness.community(m182_friend_no_iso)
friend_comm_eb
## IGRAPH clustering edge betweenness, groups: 3, mod: 0.28
## + groups:
##   $`1`
##   [1] "1"  "9"  "10" "12" "15"
##   
##   $`2`
##   [1] "2"  "7"  "8"  "13" "14"
##   
##   $`3`
##   [1] "3"  "5"  "6"  "11"
## 
plot(as.dendrogram(friend_comm_eb))

Question 3 - How many clusters would you select here and why?

I would say that there are 6 clusters as follows: group 1: 6, 11 group 2: 3, 5 group 3: 12, 15 group 4: 1, 9, 10 group 5: 8, 13, 14 group 6: 2, 7 This would be based on the distance. For example points 15 and 12 are more similar to each other than 10, 9 , or 1 therefore I put them in one cluster and the rest of them in another cluster. Similarly 8, 13, and 14 are more similar to each other therefore they form one cluster and 2, 7 form another cluster.