Load data
# load igraph package
library(igraph)
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
library(sna)
## Loading required package: statnet.common
##
## Attaching package: 'statnet.common'
## The following object is masked from 'package:base':
##
## order
## Loading required package: network
## network: Classes for Relational Data
## Version 1.13.0.1 created on 2015-08-31.
## copyright (c) 2005, Carter T. Butts, University of California-Irvine
## Mark S. Handcock, University of California -- Los Angeles
## David R. Hunter, Penn State University
## Martina Morris, University of Washington
## Skye Bender-deMoll, University of Washington
## For citation information, type citation("network").
## Type help("network-package") to get started.
##
## Attaching package: 'network'
## The following objects are masked from 'package:igraph':
##
## %c%, %s%, add.edges, add.vertices, delete.edges,
## delete.vertices, get.edge.attribute, get.edges,
## get.vertex.attribute, is.bipartite, is.directed,
## list.edge.attributes, list.vertex.attributes,
## set.edge.attribute, set.vertex.attribute
## sna: Tools for Social Network Analysis
## Version 2.4 created on 2016-07-23.
## copyright (c) 2005, Carter T. Butts, University of California-Irvine
## For citation information, type citation("sna").
## Type help(package="sna") to get started.
##
## Attaching package: 'sna'
## The following objects are masked from 'package:igraph':
##
## betweenness, bonpow, closeness, components, degree,
## dyad.census, evcent, hierarchy, is.connected, neighborhood,
## triad.census
#install.packages("statnet")
#install.packages("blockmodeling", dependencies = TRUE)
#install.packages("devtools", dependencies = TRUE)
library(devtools)
#devtools::install_github("aslez/concoR")
#Once you have installed the packages, you should be able to load them.
# Load all required packages
library(statnet, quietly = TRUE)
##
## ergm: version 3.9.4, created on 2018-08-15
## Copyright (c) 2018, Mark S. Handcock, University of California -- Los Angeles
## David R. Hunter, Penn State University
## Carter T. Butts, University of California -- Irvine
## Steven M. Goodreau, University of Washington
## Pavel N. Krivitsky, University of Wollongong
## Martina Morris, University of Washington
## with contributions from
## Li Wang
## Kirk Li, University of Washington
## Skye Bender-deMoll, University of Washington
## Based on "statnet" project software (statnet.org).
## For license and citation information see statnet.org/attribution
## or type citation("ergm").
## NOTE: Versions before 3.6.1 had a bug in the implementation of the
## bd() constriant which distorted the sampled distribution somewhat.
## In addition, Sampson's Monks datasets had mislabeled vertices. See
## the NEWS and the documentation for more details.
##
## Attaching package: 'ergm'
## The following objects are masked from 'package:statnet.common':
##
## colMeans.mcmc.list, sweep.mcmc.list
##
## networkDynamic: version 0.9.0, created on 2016-01-12
## Copyright (c) 2016, Carter T. Butts, University of California -- Irvine
## Ayn Leslie-Cook, University of Washington
## Pavel N. Krivitsky, University of Wollongong
## Skye Bender-deMoll, University of Washington
## with contributions from
## Zack Almquist, University of California -- Irvine
## David R. Hunter, Penn State University
## Li Wang
## Kirk Li, University of Washington
## Steven M. Goodreau, University of Washington
## Jeffrey Horner
## Martina Morris, University of Washington
## Based on "statnet" project software (statnet.org).
## For license and citation information see statnet.org/attribution
## or type citation("networkDynamic").
##
## tergm: version 3.5.2, created on 2018-08-18
## Copyright (c) 2018, Pavel N. Krivitsky, University of Wollongong
## Mark S. Handcock, University of California -- Los Angeles
## with contributions from
## David R. Hunter, Penn State University
## Steven M. Goodreau, University of Washington
## Martina Morris, University of Washington
## Nicole Bohme Carnegie, New York University
## Carter T. Butts, University of California -- Irvine
## Ayn Leslie-Cook, University of Washington
## Skye Bender-deMoll
## Li Wang
## Kirk Li, University of Washington
## Based on "statnet" project software (statnet.org).
## For license and citation information see statnet.org/attribution
## or type citation("tergm").
##
## ergm.count: version 3.3.0, created on 2018-08-25
## Copyright (c) 2018, Pavel N. Krivitsky, University of Wollongong
## with contributions from
## Mark S. Handcock, University of California -- Los Angeles
## David R. Hunter, Penn State University
## Based on "statnet" project software (statnet.org).
## For license and citation information see statnet.org/attribution
## or type citation("ergm.count").
## NOTE: The form of the term 'CMP' has been changed in version 3.2
## of 'ergm.count'. See the news or help('CMP') for more information.
##
## statnet: version 2018.10, created on 2018-10-17
## Copyright (c) 2018, Mark S. Handcock, University of California -- Los Angeles
## David R. Hunter, Penn State University
## Carter T. Butts, University of California -- Irvine
## Steven M. Goodreau, University of Washington
## Pavel N. Krivitsky, University of Wollongong
## Skye Bender-deMoll
## Martina Morris, University of Washington
## Based on "statnet" project software (statnet.org).
## For license and citation information see statnet.org/attribution
## or type citation("statnet").
## unable to reach CRAN
library(igraph, quietly = TRUE)
library(concoR, quietly = TRUE)
setwd("~/Penn State Data Analytics/INSC846-Network Predictive Analytics")
#load data
tribalnet <-as.matrix(read.csv("846 Lesson 10 Afghan Tribal Network Kinship-2.csv", header = T, row.names = 1, as.is=T))
head(tribalnet)
## Abdullahzai Achakzai Adozai Agha.Khel Ahmadzai Ali.Khel
## Abdullahzai 0 0 0 0 0 0
## Achakzai 0 0 1 0 0 0
## Adozai 0 1 0 0 0 0
## Agha Khel 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0
## Alikozai Alizai Alozai Andar Ashazai Ayupzai Babakzai Babozai
## Abdullahzai 0 0 0 0 0 0 0 0
## Achakzai 0 0 0 0 1 0 0 0
## Adozai 0 0 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0 0 0
## Babozai.2 badinzai Badozai Baluch Bamizai Barakzai Barechi
## Abdullahzai 0 0 0 0 0 1 0
## Achakzai 0 1 0 0 0 1 0
## Adozai 0 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0 0
## Bayezai Brahui Charar.Aimak Dai.Chopan Dai.Khitai Dai.Kundi
## Abdullahzai 0 0 0 0 0 0
## Achakzai 0 0 0 0 0 0
## Adozai 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0
## Dai.Zangi Daoudzai Dinar.Khel Durrani Durzai Faoladi Ghilzai
## Abdullahzai 0 0 0 0 0 0 0
## Achakzai 0 0 0 0 0 0 0
## Adozai 0 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0 1
## Ahmadzai 0 0 0 0 0 0 1
## Ali-Khel 0 0 0 0 0 0 1
## Ghorizai Ghur.Ghust Gurjizai Hasanzai Hasanzai.2 Hazara Hotaki
## Abdullahzai 0 0 0 0 0 0 0
## Achakzai 0 0 0 0 0 0 0
## Adozai 0 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0 0
## Ishaqzai ishaqzai.2 Jaghuri Jalizai Jalozai Kakar kakozai
## Abdullahzai 0 0 0 0 0 0 0
## Achakzai 0 1 0 1 0 0 1
## Adozai 0 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0 0
## Karimzai Karlani Khakhu.Gohraih Kharoti Khogiani Kuchi
## Abdullahzai 0 0 0 0 0 0
## Achakzai 1 0 0 0 0 0
## Adozai 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0
## Lodhil.Ludin Lodi.Powindah Machinzai Maduzai Malizai Mohakzai
## Abdullahzai 0 0 0 0 0 0
## Achakzai 0 0 0 0 1 1
## Adozai 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0
## Mohammadzai Mullah.Khel Nasir Niazy Nikozai Nokurzai
## Abdullahzai 0 0 0 0 0 0
## Achakzai 0 0 0 1 1 0
## Adozai 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0
## Nurundinzai Nurzai Nustratzai Nuur.Khel Panjpao Pashtun Polada
## Abdullahzai 0 0 0 0 0 0 0
## Achakzai 0 0 0 0 0 0 0
## Adozai 0 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0 0
## Popalzai Ruknudinzai Sadozai Sayed Shagasai Sheikh.Miran
## Abdullahzai 0 0 0 0 0 0
## Achakzai 0 0 0 0 0 0
## Adozai 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0
## Sulaiman.Khel Sultanzai Taimani Tajik Taraki Tokhi Turan
## Abdullahzai 0 0 0 0 0 0 0
## Achakzai 0 0 0 0 0 0 0
## Adozai 0 0 0 0 0 0 0
## Agha Khel 0 0 0 0 0 0 0
## Ahmadzai 0 0 0 0 0 0 0
## Ali-Khel 0 0 0 0 0 0 0
## Uruzgani Usmanzai Wardak Zalakzai Zirak
## Abdullahzai 0 0 0 0 0
## Achakzai 0 1 0 0 1
## Adozai 0 0 0 0 0
## Agha Khel 0 0 0 0 0
## Ahmadzai 0 0 0 0 0
## Ali-Khel 0 0 0 0 0
dim(tribalnet)
## [1] 91 91
colnames(tribalnet) <-c(1:91)
rownames(tribalnet) <-c(1:91)
Create network
# create a directed network
g <-graph_from_adjacency_matrix(tribalnet, mode="undirected")
# Load statnet data
net <- network(tribalnet, directed=FALSE, matrix.type="adjacency")
Hint: This is fairly straightforward, you just need to read in the provided CSV file and use the matrix to create the graph along with the plot of the network. Since the network plot can get a little busy, I have found the following configuration of plot parameters to be helpful to achieve a relatively clean layout:
plot(g, vertex.size=2, vertex.label.cex=.5, vertex.label.color="black", vertex.label.dist=1, layout =layout_with_fr, asp=0, rescale = TRUE, main="Afghan Tribal Network")
# Cluster the network based on Euclidean distance
flo.clusters <-equiv.clust(net, method="euclidean", mode="graph")
# Form blocks based on clusters
flo.blks<-blockmodel(net, flo.clusters, k = 4, mode = "graph")
flo.blks
##
## Network Blockmodel:
##
## Block membership:
##
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
## 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1
## 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
## 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
## 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
## 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##
## Reduced form blockmodel:
##
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
## Block 1 Block 2 Block 3 Block 4
## Block 1 0.01253918 0.1477273 0.1136364 0.2727273
## Block 2 0.14772727 NaN 1.0000000 0.0000000
## Block 3 0.11363636 1.0000000 NaN 0.0000000
## Block 4 0.27272727 0.0000000 0.0000000 NaN
For each of these measures, what observations can you make on the structural similarity of the blocks: Smaller or 0 Euclidean distance means actors are similar to each other and, therefore, structurally equivalent Block 1 is more similar to block 2 and 3 and most different than block 4. Block 2 and block 3 are the most different while block 2 is more similar to block 4. Block 3 is most similar to block 4, followed by block 1 and most different from block 2. Block 4 is similar to block 2 and block 3. ## We can visualize the block model in statnet.
# Plot blocks
par(ps = 6, cex = 0.75, cex.main = 1.5, col.main='white')
plot(flo.blks)
par(col.main='black')
title(main="Tribal Network")
We can plot the graph.
V(g)[flo.blks$plabels]$color <- flo.blks$block.membership
plot(g, vertex.color=V(g)$color)
CONCOR
diag(tribalnet) <- 1
flo.blks <- concor_hca(list(tribalnet), p = 2)
flo.blks
## block vertex
## 1 1 1
## 2 1 2
## 3 1 3
## 61 3 4
## 62 3 5
## 63 3 6
## 4 1 7
## 26 2 8
## 64 3 9
## 65 3 10
## 5 1 11
## 27 2 12
## 28 2 13
## 29 2 14
## 66 3 15
## 6 1 16
## 30 2 17
## 84 4 18
## 31 2 19
## 7 1 20
## 8 1 21
## 9 1 22
## 32 2 23
## 33 2 24
## 34 2 25
## 35 2 26
## 36 2 27
## 37 2 28
## 38 2 29
## 67 3 30
## 85 4 31
## 39 2 32
## 40 2 33
## 68 3 34
## 69 3 35
## 86 4 36
## 10 1 37
## 41 2 38
## 42 2 39
## 43 2 40
## 70 3 41
## 44 2 42
## 11 1 43
## 45 2 44
## 12 1 45
## 46 2 46
## 71 3 47
## 13 1 48
## 14 1 49
## 87 4 50
## 88 4 51
## 72 3 52
## 73 3 53
## 89 4 54
## 74 3 55
## 75 3 56
## 47 2 57
## 48 2 58
## 15 1 59
## 16 1 60
## 17 1 61
## 76 3 62
## 77 3 63
## 18 1 64
## 19 1 65
## 49 2 66
## 20 1 67
## 50 2 68
## 21 1 69
## 78 3 70
## 51 2 71
## 90 4 72
## 52 2 73
## 53 2 74
## 22 1 75
## 54 2 76
## 91 4 77
## 23 1 78
## 55 2 79
## 79 3 80
## 56 2 81
## 57 2 82
## 58 2 83
## 80 3 84
## 81 3 85
## 82 3 86
## 59 2 87
## 24 1 88
## 83 3 89
## 60 2 90
## 25 1 91We can also visualize the blocks by coloring and plotting the network.
plot(g, vertex.color=flo.blks$block)
We can also create a graph from the reduced block model that collapses all the actors in a block into a single node.
flo.blks$block[is.na(flo.blks$block)] <- 0
flo.mod <- blockmodel(net, flo.blks$block)
flo.mod
##
## Network Blockmodel:
##
## Block membership:
##
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
## 1 1 1 3 3 3 1 2 3 3 1 2 2 2 3 1 2 4 2 1 1 1 2 2 2
## 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
## 2 2 2 2 3 4 2 2 3 3 4 1 2 2 2 3 2 1 2 1 2 3 1 1 4
## 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
## 4 3 3 4 3 3 2 2 1 1 1 3 3 1 1 2 1 2 1 3 2 4 2 2 1
## 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
## 2 4 1 2 3 2 2 2 3 3 3 2 1 3 2 1
##
## Reduced form blockmodel:
##
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
## Block 1 Block 2 Block 3 Block 4
## Block 1 0.086666667 0.001142857 0.00000000 0.010000000
## Block 2 0.001142857 0.048739496 0.00000000 0.003571429
## Block 3 0.000000000 0.000000000 0.09486166 0.027173913
## Block 4 0.010000000 0.003571429 0.02717391 0.285714286
g.reduced <- graph_from_adjacency_matrix(flo.mod$block.model, weighted=TRUE, mode="undirected")
plot(simplify(g.reduced))
What observations can you make on the structural similarity of the blocks? Using the the reduced form blockmodel from concoR, block 1 is most similar to block 3, followed by block 2 and block 4. Block 2 is similar to block 3. Block 3 is most different from block 4. ## iii. Optimization
# Load required library
library(blockmodeling)
## To cite package 'blockmodeling' in publications please use package
## citation and (at least) one of the articles:
##
## Žiberna, Aleš (2007). Generalized blockmodeling of valued
## networks. Social Networks 29(1), 105-126.
##
## Žiberna, Aleš (2008). Direct and indirect approaches to
## blockmodeling of valued networks in terms of regular
## equivalence. Journal of Mathematical Sociology 32(1), 57–84.
##
## Ziberna, Ales (2018). Generalized and Classical Blockmodeling
## of Valued Networks, R package version 0.3.4.
##
## To see these entries in BibTeX format, use 'print(<citation>,
## bibtex=TRUE)', 'toBibtex(.)', or set
## 'options(citation.bibtex.max=999)'.
##
## Attaching package: 'blockmodeling'
## The following object is masked from 'package:sna':
##
## sedist
# Try partitioning into two blocks
# flo.2blks <- opt.random.par(M=flo, k=2, rep=10, approach="ss", blocks="com")
flo.2blks <- optRandomParC(M=tribalnet, k=2, rep=10, approaches="hom", homFun="ss", blocks="com")
##
##
## Starting optimization of the partiton 1 of 10 partitions.
## Starting partition: 1 1 1 1 2 1 2 1 2 1 1 1 1 1 2 2 2 2 2 2 2 2 1 2 1 1 2 1 1 2 2 2 1 2 2 1 2 2 2 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 2 2 2 2 1 1 1 2 2 2 1 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2
## Final error: 165.8711
## Final partition: 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
##
##
## Starting optimization of the partiton 2 of 10 partitions.
## Starting partition: 1 1 1 2 1 2 2 2 2 1 1 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 1 1 1 1 2 1 1 2 1 1 2 2 1 1 1 2 1 2 2 1 2 2 1 1 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 2 1 2
## Final error: 165.8711
## Final partition: 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
##
##
## Starting optimization of the partiton 3 of 10 partitions.
## Starting partition: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
## Final error: 165.8711
## Final partition: 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
##
##
## Starting optimization of the partiton 4 of 10 partitions.
## Starting partition: 1 1 2 1 2 1 2 1 1 1 2 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 1 1 1 1 1 2 1 2 2 1 2 2 2 2 2 2 1 2 1 1 1 1 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 2 1 2 1 1
## Final error: 165.8711
## Final partition: 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
##
##
## Starting optimization of the partiton 5 of 10 partitions.
## Starting partition: 1 1 1 1 1 1 2 2 1 2 2 1 2 1 2 2 1 1 1 1 2 1 1 2 2 1 1 1 1 1 2 2 2 1 1 2 1 2 1 2 2 2 2 1 2 1 1 1 2 1 1 1 2 2 1 1 1 2 1 1 2 2 1 2 2 2 2 2 1 2 2 1 1 2 1 2 1 1 2 2 2 2 1 2 2 1 1 2 2 2 1
## Final error: 165.8711
## Final partition: 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
##
##
## Starting optimization of the partiton 6 of 10 partitions.
## Starting partition: 2 2 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 2 2 1 1 1 2 1 1 1 1 1 1 2 2 2 1 2 2 1 2 2 2 2 2 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 2 2 2 1 1 2 1 2 2 1 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1
## Final error: 165.8711
## Final partition: 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
##
##
## Starting optimization of the partiton 7 of 10 partitions.
## Starting partition: 2 1 2 1 1 2 1 1 2 2 1 1 2 1 2 2 1 1 1 1 1 1 1 2 2 1 2 2 1 2 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 1 2 1 2 1 2 2 1 1 2 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 2 2 2 1 1 1 1 2 1 2 1
## Final error: 165.8711
## Final partition: 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
##
##
## Starting optimization of the partiton 8 of 10 partitions.
## Starting partition: 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 1 2 2 1 2 1 2 2 2 1 1 1 2 2 1 2 2 1 1 2 2 1 2 2 1 2 2 2 2 1 2 2 1 2 2 1 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 1 1 1 2 1 2 1 2 2 1 1 1 1 2 1 1 2 2 2 2 2 1 2 2 2
## Final error: 165.8711
## Final partition: 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##
##
## Starting optimization of the partiton 9 of 10 partitions.
## Starting partition: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
## Final error: 165.8711
## Final partition: 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
##
##
## Starting optimization of the partiton 10 of 10 partitions.
## Starting partition: 1 2 1 1 2 2 1 2 2 2 1 1 1 1 2 1 1 2 1 2 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 1 1 2 1 1 2 1 2 1 2 2 2 2 2 2 1 2 2 1 2 1 2 2 2 1 2 2 1 2 1 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 1 1 1 2 1 1 1 2 1 1
## Final error: 165.8711
## Final partition: 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
##
##
## Optimization of all partitions completed
## All 10 solutions have err 165.8711
# Try partitioning into four blocks
#flo.4blks <- opt.random.par(M=flo, k=4, rep=10, approach="ss", blocks="com")
flo.4blks <- optRandomParC(M=tribalnet, k=4, rep=10, approaches="hom", homFun="ss", blocks="com")
##
##
## Starting optimization of the partiton 1 of 10 partitions.
## Starting partition: 2 3 1 1 1 3 1 1 4 2 1 1 3 1 1 2 1 3 1 2 2 3 2 3 4 3 3 2 1 2 1 4 2 3 4 2 1 2 1 2 4 3 1 3 4 2 3 2 3 1 2 2 1 2 3 3 4 4 2 2 3 4 1 2 1 1 3 1 2 2 1 1 2 4 1 2 1 3 4 1 1 1 2 3 3 1 4 1 1 4 3
## Final error: 145.0204
## Final partition: 4 3 4 4 4 4 2 2 4 4 4 2 2 2 4 4 2 2 2 3 4 4 2 2 2 2 2 2 2 4 1 2 2 3 4 2 4 2 2 2 4 2 4 2 4 2 4 4 4 2 2 4 4 1 4 4 2 2 4 4 4 4 4 4 4 2 4 2 4 4 2 1 2 2 4 2 2 4 2 4 2 2 2 4 4 4 2 4 4 2 4
##
##
## Starting optimization of the partiton 2 of 10 partitions.
## Starting partition: 3 2 4 3 3 3 2 2 2 1 1 3 1 3 2 2 1 2 1 3 2 3 4 3 2 1 1 1 3 4 1 2 2 4 3 3 1 3 3 1 4 3 4 3 4 3 3 3 4 4 2 4 2 2 1 1 4 2 3 1 2 4 4 3 2 3 2 1 3 1 3 1 3 3 3 1 3 4 2 1 4 2 2 1 1 4 1 4 2 3 1
## Final error: 147.773
## Final partition: 3 2 4 3 3 3 4 4 3 3 4 4 4 4 3 4 4 4 4 1 3 3 4 4 3 3 3 3 2 3 2 4 3 1 3 4 3 4 4 1 3 4 4 3 4 4 3 4 4 4 4 3 3 2 3 3 4 4 4 4 3 3 3 4 4 4 3 2 3 3 2 2 3 2 3 4 4 3 3 3 4 4 4 3 3 3 3 4 3 4 4
##
##
## Starting optimization of the partiton 3 of 10 partitions.
## Starting partition: 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 4 4 2 4 4 4 4 4 4 4 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
## Final error: 126.0442
## Final partition: 4 1 4 3 3 3 4 4 3 3 4 4 4 4 3 4 4 4 4 1 4 4 4 4 4 4 4 4 4 3 4 4 4 2 3 4 4 4 4 1 3 4 4 4 4 4 3 4 4 4 4 3 3 3 3 3 4 4 4 4 4 3 3 4 4 4 4 1 4 3 4 3 4 1 4 4 4 4 4 3 4 4 4 3 3 3 4 4 3 4 4
##
##
## Starting optimization of the partiton 4 of 10 partitions.
## Starting partition: 4 3 4 1 4 1 4 2 3 4 4 3 1 2 2 4 2 2 2 1 3 3 1 1 4 3 1 3 2 4 1 1 4 2 3 4 1 1 3 2 2 4 3 4 1 4 4 2 3 4 1 3 4 3 3 2 3 2 3 4 1 2 2 3 1 4 2 3 1 4 1 3 1 4 2 2 1 3 3 2 3 2 4 4 2 1 2 3 2 1 1
## Final error: 148.8126
## Final partition: 1 2 4 4 4 4 1 1 4 4 4 1 3 3 4 4 1 1 1 1 1 1 1 1 4 4 4 4 3 4 1 3 4 2 4 1 1 1 1 2 4 3 4 4 4 1 4 4 4 1 1 4 4 4 4 4 3 3 4 4 1 4 4 4 4 3 1 3 1 4 3 4 4 1 1 1 1 1 4 4 3 1 1 4 4 4 4 4 4 3 1
##
##
## Starting optimization of the partiton 5 of 10 partitions.
## Starting partition: 2 4 3 2 3 2 1 1 1 2 4 4 4 1 4 3 3 2 4 2 3 1 2 3 3 4 4 4 2 1 4 2 2 1 2 4 2 3 3 3 1 2 1 3 4 4 2 3 3 1 1 2 3 1 3 1 4 2 1 1 3 1 3 2 3 3 4 4 2 2 4 1 2 1 2 3 4 1 1 3 2 1 4 3 4 4 4 1 3 4 2
## Final error: 131.7689
## Final partition: 2 2 3 4 4 4 3 3 4 4 3 2 3 2 4 3 2 3 2 3 2 2 3 3 3 3 3 3 2 4 3 2 3 1 4 3 2 2 2 2 4 3 3 3 3 2 4 3 3 3 3 4 4 4 4 4 3 2 3 3 2 4 4 3 3 2 2 3 2 4 2 4 3 3 2 2 2 2 3 4 3 2 3 4 4 4 3 3 4 3 2
##
##
## Starting optimization of the partiton 6 of 10 partitions.
## Starting partition: 4 3 2 4 2 2 1 2 2 1 3 4 2 4 3 1 1 2 1 2 2 3 1 3 2 3 3 2 1 1 1 1 3 1 1 4 1 3 4 2 3 2 4 3 2 2 4 1 3 4 4 2 1 4 4 4 4 3 3 3 3 4 1 2 4 3 3 2 4 3 1 3 2 4 1 2 3 4 1 2 3 2 4 4 4 2 1 1 3 1 1
## Final error: 148.4105
## Final partition: 3 2 3 3 3 3 4 4 3 3 3 4 4 4 3 3 4 4 4 2 3 3 4 4 3 3 3 3 4 3 1 4 3 2 3 4 3 4 4 2 3 4 3 3 3 4 3 3 3 4 4 3 3 1 3 3 4 4 3 3 3 3 3 3 3 4 3 4 3 3 4 1 3 4 3 4 4 3 3 3 4 4 4 3 3 3 3 3 3 4 3
##
##
## Starting optimization of the partiton 7 of 10 partitions.
## Starting partition: 2 4 3 1 4 1 4 1 3 1 1 4 2 4 2 2 4 3 1 3 2 1 1 4 4 1 1 1 3 2 1 4 1 1 3 1 2 2 4 3 4 1 2 1 1 1 3 1 4 1 4 4 4 4 3 1 2 4 1 4 3 1 4 4 1 1 2 2 3 3 4 3 4 1 3 2 4 4 2 1 3 2 1 4 3 4 4 4 2 3 4
## Final error: 148.4105
## Final partition: 2 3 2 2 2 2 4 4 2 2 2 4 4 4 2 2 4 4 4 3 2 2 4 4 2 2 2 2 4 2 1 4 2 3 2 4 2 4 4 3 2 4 2 2 2 4 2 2 2 4 4 2 2 1 2 2 4 4 2 2 2 2 2 2 2 4 2 4 2 2 4 1 2 4 2 4 4 2 2 2 4 4 4 2 2 2 2 2 2 4 2
##
##
## Starting optimization of the partiton 8 of 10 partitions.
## Starting partition: 2 2 3 3 2 3 3 2 4 3 3 4 4 1 2 4 1 3 4 3 2 4 3 1 1 2 2 1 3 4 1 2 2 2 4 2 2 4 4 1 1 1 3 4 2 1 3 4 4 3 3 1 1 2 1 1 4 4 1 2 4 1 1 2 3 4 1 4 1 4 3 1 3 2 2 4 2 3 1 4 2 3 3 2 4 1 4 3 1 2 3
## Final error: 139.3839
## Final partition: 3 2 4 4 4 4 3 3 4 4 4 3 3 3 4 4 3 3 3 1 3 3 3 3 3 3 3 3 1 4 3 3 3 2 4 3 3 3 3 1 4 3 4 3 4 3 4 4 4 3 3 4 4 4 4 4 3 3 4 4 3 4 4 4 4 3 3 3 3 4 1 4 3 1 3 3 3 3 3 4 3 3 3 4 4 4 3 4 4 3 3
##
##
## Starting optimization of the partiton 9 of 10 partitions.
## Starting partition: 4 4 4 3 1 3 3 4 2 4 2 3 3 2 4 1 1 2 4 2 3 1 3 1 1 1 2 1 2 4 1 2 3 4 3 1 4 2 4 1 3 4 1 2 3 1 2 3 3 3 4 2 3 4 4 2 2 3 3 1 4 2 1 4 3 3 4 2 3 1 4 1 1 2 2 3 4 1 1 1 3 2 2 4 2 4 1 2 1 2 3
## Final error: 143.4718
## Final partition: 2 4 3 3 3 3 2 1 3 3 3 2 2 2 3 3 2 2 2 2 2 2 2 1 1 1 1 1 2 3 1 2 1 4 3 2 2 1 2 1 3 1 3 1 3 1 3 3 3 2 2 3 3 3 3 3 2 1 3 3 2 3 3 3 3 2 2 2 2 3 1 3 1 2 2 2 1 2 1 3 2 1 2 3 3 3 1 3 3 2 2
##
##
## Starting optimization of the partiton 10 of 10 partitions.
## Starting partition: 3 1 1 3 1 4 2 2 4 4 4 2 3 4 3 4 2 2 3 1 4 4 2 4 3 2 2 3 4 3 4 4 1 3 2 4 2 2 4 4 1 4 1 1 1 3 2 1 1 1 1 2 3 3 4 3 1 2 3 2 1 3 2 1 3 4 3 3 2 1 3 2 2 3 2 1 4 4 1 1 1 3 2 3 4 1 4 4 1 2 2
## Final error: 149.3125
## Final partition: 2 1 2 2 2 2 2 2 2 2 2 3 2 3 2 2 3 2 3 1 2 2 2 2 3 3 3 3 3 2 2 3 3 1 2 2 2 2 3 4 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 4 2 2 3 2 3 4 2 3 2 2 3 2 2 2 2 2 2 2 3 2 2 2 2
##
##
## Optimization of all partitions completed
## 1 solution(s) with minimal error = 126.0442 found.
We can plot these side-by-side to compare them.
# Set the plot window for one row and two columns
par(mfrow=c(1,2))
plot(flo.2blks, main="")
title("Two Block Partition")
plot(flo.4blks, main="")
title("Four Block Partition")
We can visualize the network the same way as before.
plot(g, vertex.color=flo.4blks$best$best1$clu)
34 is connected to the most, while 2,20,74,71,29 and 40 are connected to the next most connections. The rest in blue are connected to one or less. ## Regular Equivalence: #REGE returns similarities, which have to be converted to disimilarities
library(blockmodeling)
D<-REGE(M=tribalnet)$E
plot.mat(tribalnet, clu=cutree(hclust(d=as.dist(1-D), method="ward.D"), k=4))
We can try another variation of REGE.
# Try another variation of REGE
D2<-REGE.ownm.for(M=tribalnet)$E
plot.mat(tribalnet, clu=cutree(hclust(d=as.dist(1-D2),method="ward.D"),
k=4))
Let us visualize the network to make sense of these blocks.
clu <- cutree(hclust(d=as.dist(1-D2),method="ward.D"), k=4)
V(g)[names(clu)]$color <- clu
plot(g, vertex.color=V(g)$color)
What observations can you make on the Regular Equivalence of the blocks: On the edges of the network form a block (shown in gold); their role could be that of a source or a sink. Those in brokerage position form another group (one group shown in yellow and the other shown in green); their role could be like those of the repeaters. Those having connections to most of the brokers form another group (shown in blue); their role could be that of a source or a sink.