class: center, middle, inverse, title-slide # POL 478H1 F ## Intro to Network Analysis ### Olga Chyzh [www.olgachyzh.com] --- ## Today's Class **Network Analysis: an introduction** 1. Definitions. What is network analysis? 3. Network features and measurements 4. Collecting/managing network data 5. Applications to Political Science 6. Network Visualization --- ## What is a network (i.e., a graph)? A set of **nodes** and **relation(s)** defined on them <img src="images/madmen.png" width="400px" style="display: block; margin: auto;" /> --- ## Defining Network Features & Measurements: What's a node? - A <span style="color:DarkCyan">**node**</span> can be defined as an entity that can form relations with other entities. **Synonyms**: - actor: from sociometry, common terminology in sociology and psychology - vertex: from graph theory (i.e., math), common terminology in mathematics and physics Term node is common in statistics and applied sciences outside of soc and psych. --- ## Examples of Nodes - Individuals (Mad Men characters, legislators, terrorists) - Families - Organizations, Human Rights NGOs - Countries --- ## Defining Network Features & Measurements: What's a relation? - A <span style="color:DarkCyan">**relation/tie**</span> defines the existence of an attribute relating nodes. **Synonyms**: - link: common in computer science (e.g., huge lit on “Link Prediction”) and social sciences - edge: graph theoretic terminology common in physics and math, but also elsewhere **Ties can have characteristics**: - Weight - Qualitative attributes - Direction --- ## Exampesl of Ties - Romantic relationship, marriage, friendship - Business relationship - Cooperation/conflict --- ## Network graphs can reveal important structures <div class="figure" style="text-align: center"> <img src="images/p1.png" alt=" " width="49%" height="10%" /><img src="images/p2.png" alt=" " width="49%" height="10%" /> <p class="caption"> </p> </div> --- ## Adolescent romantic and sexual networks <img src="images/jefferson.jpg" width="600px" style="display: block; margin: auto;" /> **Bearman, Moody and Stovel** --- ## Adolescent Social Structure by **Jim Moody** <img src="images/schoolGrade.png" width="600px" style="display: block; margin: auto;" /> --- ## Adolescent Social Structure by **Jim Moody** <img src="images/schoolRace.png" width="600px" style="display: block; margin: auto;" /> --- ## Managing Network Data You might begin with either a matrix or information stored separately about edges and nodes. This depends on your data collection strategy. Useful terminology for working in `\(R\)`: + Matrices: the adjacency matrix + Edges: linkages between actors or nodes + Vertices: nodes (or actors) in your system --- ## Example: International Alliances 1914 Download the data [here](https://raw.githubusercontent.com/ochyzh/POLS478/master/defmat1914.csv) - Countries are nodes - Alliances are ties ```r defMat<-read.csv("https://raw.githubusercontent.com/ochyzh/POLS478/master/defmat1914.csv" , header=T) head(defMat) ``` ``` ## name1 name2 ally ## 1 AUH GUA 0 ## 2 AUH HON 0 ## 3 AUH SAL 0 ## 4 AUH NIC 0 ## 5 AUH ECU 0 ## 6 AUH UKG 0 ``` --- ## Your Turn (5 min) Can you transform `defAlly` into a matrix form as shown below? ```r as.matrix(defMat)[1:20,1:20] ``` ``` ## AUH BOL BUL COS ECU FRN GMY GRC GUA HON ITA JPN MNG NIC POR ROM RUS SAL ## [1,] NA 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 ## [2,] 0 NA 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ## [3,] 1 0 NA 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 ## [4,] 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ## [5,] 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0 0 0 ## [6,] 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 1 0 ## [7,] 1 0 1 0 0 0 NA 0 0 0 1 0 0 0 0 1 0 0 ## [8,] 0 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 ## [9,] 0 0 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 ## [10,] 0 0 0 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 ## [11,] 1 0 0 0 0 0 1 0 0 0 NA 0 0 0 0 0 0 0 ## [12,] 0 0 0 0 0 0 0 0 0 0 0 NA 0 0 0 0 0 0 ## [13,] 0 0 0 0 0 0 0 0 0 0 0 0 NA 0 0 0 0 0 ## [14,] 0 0 0 0 0 0 0 0 0 0 0 0 0 NA 0 0 0 0 ## [15,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NA 0 0 0 ## [16,] 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 NA 1 0 ## [17,] 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 NA 0 ## [18,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NA ## [19,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ## [20,] 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 ## SPN TUR ## [1,] 0 0 ## [2,] 0 0 ## [3,] 0 1 ## [4,] 0 0 ## [5,] 0 0 ## [6,] 0 0 ## [7,] 0 1 ## [8,] 0 0 ## [9,] 0 0 ## [10,] 0 0 ## [11,] 0 0 ## [12,] 0 0 ## [13,] 0 0 ## [14,] 0 0 ## [15,] 0 0 ## [16,] 0 0 ## [17,] 0 0 ## [18,] 0 0 ## [19,] NA 0 ## [20,] 0 NA ``` --- ## Make a Network Graph ```r library(igraph) pGraph <- graph_from_adjacency_matrix(as.matrix(defMat), weighted=NULL, mode="undirected", diag=FALSE) #convert to an igraph object pGraph <- delete.vertices(pGraph , which(degree(pGraph)==0)) #remove isolates V(pGraph)$color <- "turquoise" AllyPlot<- plot(pGraph, edge.arrow.size=.2, edge.color="black", vertex.frame.color="black", vertex.label=V(pGraph)$names, vertex.label.color="black", layout=layout_with_fr, edge.width=E(pGraph)$weight/5, edge.curved=.08, vertex.size=30) ``` --- ## Make a Network Graph <img src="10_networks_files/figure-html/unnamed-chunk-11-1.png" style="display: block; margin: auto;" />