Group Composition:

The data used for this project is Formal Alliances version 4.1, specifically arranged by dyad and can be found on the following link: https://correlatesofwar.org/data-sets/formal-alliances/alliances-data-csv-zip/at_download/file

Data collection and implementation

Loading libraries

library("network")
library("ggnetwork")
library("sna")
library("dplyr")
library("knitr")
library("tibble")
library("ggrepel")
library("ggraph")


setwd("C:/Users/jebet/OneDrive/Escritorio/UEXT/ULB/Social network analysis/Directory")
all_data <- read.table("alliance_v4.1_by_dyad.csv", sep=",", header=TRUE, na.strings="", stringsAsFactors = FALSE)
View(all_data)

Functions

We made functions to create easier subsets, in order to be able to use measures and plot the mentioned data.

subseting <- function(start_d, end_d){

  sub <- subset(all_data,
                     asymmetric == 0 & defense == 1 &
                       (dyad_st_year <= end_d | (is.na(dyad_st_year) & left_censor == 1)) & 
                       (dyad_end_year >= start_d | (is.na(dyad_end_year) & right_censor == 1)))

  country_codes <- sort(unique(c(sub$ccode1, sub$ccode2)))
  N <- length(country_codes)
  
  sub$snd <- match(sub$ccode1, country_codes)
  sub$rec <- match(sub$ccode2, country_codes)
  sub$val <- 1
  sub_edges <- sub[, c("snd", "rec", "val")]
  
  country_names_all <- data.frame(ccode = c(sub$ccode1, sub$ccode2),
                                  state = c(as.character(sub$state_name1),
                                            as.character(sub$state_name2)),
                                  stringsAsFactors = FALSE)
  
  country_names_table <- sort(unique(country_names_all))
  country_names <- country_names_table$state[match(country_codes, country_names_table$ccode)]
  
  sub_edges_b <- unique(sub_edges)
  sub_edgelist <- as.matrix(sub_edges_b) 

  attr(sub_edgelist, "n") <- N
  attr(sub_edgelist, "vnames") <- country_names
  
  sub_mat <- as.sociomatrix.sna(sub_edgelist)
  sub_net <- as.network(sub_edgelist, matrix.type = "edgelist", directed = FALSE, multiple = FALSE, edge.check = TRUE) 
}
  
plot_that <- function(sub,sub_title=""){
  
  ggplot(sub, aes(x = x, y = y, xend = xend, yend = yend)) +
    ggtitle(sub_title)+
    geom_edges(alpha = 0.5, colour = "lightgray", size = 1) +
    geom_nodetext_repel(mapping = aes(label = vertex.names),force = 5) + 
    geom_nodes() +
    theme_blank() 

  
}

central_mat <- function(sub_mat){
  
  n_sub_mat <- nrow(sub_mat)
  base_sub_df <- data.frame(Country = rownames(sub_mat), 
                            Degree = degree(sub_mat, gmode = "graph"),
                            StdDegree = degree(sub_mat, gmode = "graph")/(n_sub_mat-1),  
                            Betweenness = betweenness(sub_mat, gmode = "graph"),
                            StdBetweenness = betweenness(sub_mat, gmode = "graph")/((n_sub_mat-1)*(n_sub_mat-2)/2), stringsAsFactors = FALSE) 

} 

Subsets creation

cw_net <- subseting(1946,1989)
now_net <- subseting(1991,2012)

cw_mat <- as.sociomatrix.sna(cw_net)
now_mat <- as.sociomatrix.sna(now_net)

cw_ego <- ego.extract(cw_net)
now_ego <- ego.extract(now_net)

Constructing the networks and its properties

Adding plots

set.seed(4)
cw_coord <- fortify(cw_net, layout = "kamadakawai")
now_coord <- fortify(now_net)

plot_that(cw_coord, "Network Showing Aliances during Cold War (1947-1991)")

plot_that(now_coord, "Network Showing Aliances Between 1990 and 2012")

Centrality

Measures

base_cw_df <- central_mat(cw_mat)
base_now_df <- central_mat(now_mat)

sort_cw_df <- base_cw_df[order(base_cw_df$StdBetweenness ,decreasing = TRUE),]
sort_now_df <- base_now_df[order(base_now_df$StdBetweenness ,decreasing = TRUE),]
sort_cw_df1 <- base_cw_df[order(base_cw_df$StdBetweenness ,decreasing = TRUE),]
sort_now_df1 <- base_now_df[order(base_now_df$StdBetweenness ,decreasing = TRUE),]
sort_cw_df2 <- base_cw_df[order(base_cw_df$StdDegree ,decreasing = TRUE),]
sort_now_df2 <- base_now_df[order(base_now_df$StdDegree ,decreasing = TRUE),]
 

kable(sort_cw_df1[1:10,], digits = 2, caption = "Betweenness cw")
Betweenness cw
Country Degree StdDegree Betweenness StdBetweenness
38 France 19 0.17 1842.17 0.31
1 United States of America 48 0.44 1802.67 0.30
34 United Kingdom 17 0.15 1646.62 0.27
93 Iraq 18 0.16 1298.36 0.22
52 Russia 15 0.14 1061.99 0.18
2 Canada 39 0.35 925.00 0.15
63 Mauritania 26 0.24 480.63 0.08
74 Gabon 14 0.13 341.66 0.06
75 Central African Republic 14 0.13 341.66 0.06
76 Chad 14 0.13 341.66 0.06
kable(sort_now_df1[1:10,], digits = 2, caption = "Betweenness now")
Betweenness now
Country Degree StdDegree Betweenness StdBetweenness
39 France 19 0.15 2500.33 0.33
82 Gabon 11 0.09 2499.00 0.33
102 Sudan 26 0.21 2211.00 0.29
71 Mauritania 19 0.15 1275.00 0.17
1 United States of America 46 0.37 1142.00 0.15
2 Canada 44 0.35 945.00 0.12
85 Congo 17 0.14 448.00 0.06
94 Angola 17 0.14 448.00 0.06
83 Central African Republic 15 0.12 351.00 0.05
86 Democratic Republic of the Congo 15 0.12 351.00 0.05
kable(sort_cw_df2[1:10,], digits = 2, caption = "StdDegree cw")
StdDegree cw
Country Degree StdDegree Betweenness StdBetweenness
1 United States of America 48 0.44 1802.67 0.30
2 Canada 39 0.35 925.00 0.15
5 Haiti 31 0.28 4.67 0.00
6 Dominican Republic 31 0.28 4.67 0.00
16 Mexico 31 0.28 4.67 0.00
17 Guatemala 31 0.28 4.67 0.00
18 Honduras 31 0.28 4.67 0.00
20 Nicaragua 31 0.28 4.67 0.00
21 Costa Rica 31 0.28 4.67 0.00
22 Panama 31 0.28 4.67 0.00
kable(sort_now_df2[1:10,], digits = 2, caption  = "StdDegree now")
StdDegree now
Country Degree StdDegree Betweenness StdBetweenness
1 United States of America 46 0.37 1142 0.15
2 Canada 44 0.35 945 0.12
3 Bahamas 28 0.23 0 0.00
4 Haiti 28 0.23 0 0.00
5 Dominican Republic 28 0.23 0 0.00
6 Jamaica 28 0.23 0 0.00
8 Barbados 28 0.23 0 0.00
9 Dominica 28 0.23 0 0.00
10 Grenada 28 0.23 0 0.00
11 St. Lucia 28 0.23 0 0.00
ten_cw_df <- sort_cw_df[1:10,]
ten_now_df <- sort_now_df[1:10,]

Graphs

ggplot(data = ten_cw_df, aes(x =  StdBetweenness, y =StdDegree , label = Country)) +
  geom_point()+
  geom_label_repel(size = 5)

ggplot(data = ten_now_df, aes(x =  StdBetweenness, y =StdDegree , label = Country)) +
  geom_point()+
  geom_label_repel(size = 5)

Standard Deviation of Betweenes in the Network

ten_cw_country <- ten_cw_df$Country
ten_now_country <- ten_now_df$Country

ten_cw_mat <- cw_mat[ten_cw_country,ten_cw_country]
ten_cw_net <- as.network(ten_cw_mat,  directed = FALSE, multiple = FALSE, edge.check = TRUE)

ten_now_mat <- now_mat[ten_now_country,ten_now_country]
ten_now_net <- as.network(ten_now_mat,  directed = FALSE, multiple = FALSE, edge.check = TRUE) 


plot_that(ten_cw_net, "Most StdBetweeness during the Cold War")

plot_that(ten_now_net,"Most StdBetweeness 1990 - 2012")

#We have here graphical representation of the States with considerable betweenness during the cold war and afterwards its culmination. The graphs indicating the conflict period are labeled as "cw". 
plot_that(ggnetwork(cw_ego$France),"France cw") 

In this graph we can see a triad between France, UK and Russia. France shares arcs with countries of various regions, including Europe, Africa, America (south and north) and Russia.

plot_that(ggnetwork(now_ego$France),"France")

In this graph, France no longer has a shared arc with Russia. France also no longer has as many direct links with countries from different continents as it did before.

plot_that(ggnetwork(cw_ego$`United States of America`),"United States of America cw")

plot_that(ggnetwork(now_ego$`United States of America`),"United States of America")

The situation of the USA does not seem to have changed much; it is still an important link between two subsets (Europe and South America) and it has kept an impressive number of alliances with many countries around the world. We do know from the previous tables that the USA has somewhat fewer connections than before.

plot_that(ggnetwork(cw_ego$`United Kingdom`),"United Kingdom cw")

plot_that(ggnetwork(now_ego$`United Kingdom`),"United Kingdom")

While the UK previously had a few military alliances with countries outside of Europe, namely Iraq, Iran, and Russia, it now is part of a fully connected and closed network that only contains European countries except for the USA.

plot_that(ggnetwork(cw_ego$Russia),"Russia cw")

plot_that(ggnetwork(now_ego$Russia),"Russia")

Russia’s direct network of alliances shrinked after the Cold War, it only kept alliances with countries previously belonging to the USSR, except for North Korea and direct geographical neighbors. Ironically enough, in 2012 Russia had a military alliance with Ukraine that it did not have before.

Deepening into the subgraphs of the network

Components and communities

We will now analyse the different communities that can be found in this database.

library(igraph)

cw_graph <- intergraph::asIgraph(cw_net)
now_graph <- intergraph::asIgraph(now_net)

cw_graph_components <- components(cw_graph, mode = "strong")
now_graph_components <- components(now_graph, mode = "strong")

communities_cw <- cluster_louvain(cw_graph)
communities_now <- cluster_louvain(now_graph)

# assign component property
V(now_graph)$component <- now_graph_components$membership
V(now_graph)$community <- membership(communities_now)
V(now_graph)$degree <- degree(now_graph)

V(cw_graph)$component <- cw_graph_components$membership
V(cw_graph)$community <- membership(communities_cw)
V(cw_graph)$degree <- degree(cw_graph)
set.seed(4)
cw_for_graph <- fortify(model=cw_graph, layout=igraph::layout_with_dh(cw_graph))
set.seed(19)
now_for_graph <- fortify(model=now_graph, layout=igraph::layout_with_dh(now_graph))
ggplot(cw_for_graph, aes(x = x, y = y, xend = xend, yend = yend)) +
  geom_edges(alpha = 0.3, colour = "lightgray",size = 1) +  
  geom_nodes(aes(color = as.factor(community),size= degree)) +
  scale_size_continuous(range = c(1, 7)) +
  geom_nodetext_repel(mapping = aes(label = vertex.names),force = 5) + 
  ggtitle("Cold War Defence Relation Map 1949 - 1989 :")+
  theme_blank()

ggplot(now_for_graph, aes(x = x, y = y, xend = xend, yend = yend)) +
  geom_edges(alpha = 0.3, colour = "lightgray",size = 1) +  
  geom_nodes(aes(color = as.factor(community),size= degree)) +
   scale_size_continuous(range = c(1, 7)) +
  geom_nodetext_repel(mapping = aes(label = vertex.names),force = 5) + 
  ggtitle("Post Cold War Defence Relation Map 1990 - 2012 :")+
  theme_blank()