Week 2 Challenge Instructions

challenge_2
instructions
Describing the Basic Structure of a Network
Author

Amer Abuhasan

Published

February 22, 2023

Challenge Overview

Describe the basic structure of a network following the steps in tutorial of week 2, this time using a dataset of your choice: for instance, you could use Marriages in Game of Thrones or Like/Dislike from week 1.

Another more complex option is the newly added dataset of the US input-output table of direct requirements by industry, availabe in the Bureau of Economic Analysis. Input-output tables show the economic transactions between industries of an economy and thus can be understood as a directed adjacency matrix. Data is provided in the form of an XLSX file, so using read_xlsx from package readxl is recommended, including the sheet as an argument (2012 for instance).

Identify and describe content of nodes and links, and identify format of data set (i.e., matrix or edgelist, directed or not, weighted or not), and whether attribute data are present. Be sure to provide information about network size (e.g., information obtained from network description using week 1 network basic tutorial commands.)

Explore the dataset using commands from week 2 tutorial. Comment on the highlighted aspects of network structure such as:

  • Geodesic and Path Distances; Path Length
  • Dyads and Dyad Census
  • Triads and Triad Census
  • Network Transitivity and Clustering
  • Component Structure and Membership

Be sure to both provide the relevant statistics calculated in R, as well as your own interpretation of these statistics.

Describe the Network Data

  1. List and inspect List the objects to make sure the datafiles are working properly.
Code
ls()
character(0)
Code
got_like_dislike <- read.csv('_data/got/got_like_dislike.csv')

view(got_like_dislike)
  1. Network Size What is the size of the network? You may use vcount and ecount. #the size of the network is 11 vertices with 46 edges
Code
ls(got_like_dislike)
 [1] "Arya.Stark"            "Balon.Greyjoy"         "Bran.Stark"           
 [4] "Brienne.of.Tarth"      "Bronn"                 "Catelyn.Stark"        
 [7] "Cersei.Lannister"      "Current.house"         "Daenerys.Targaryen"   
[10] "Davos.Seaworth"        "Eddard.Stark"          "Former.house"         
[13] "Gendry"                "Grand.Maester.Pycelle" "Gregor.Clegane"       
[16] "Hodor"                 "Jaime.Lannister"       "Jaqen.H.ghar"         
[19] "Jeor.Mormont"          "Joffrey.Baratheon"     "Jon.Snow"             
[22] "Jorah.Mormont"         "Khal.Drogo"            "Lancel.Lannister"     
[25] "Loras.Tyrell"          "Lysa.Arryn"            "Maester.Luwin"        
[28] "Margaery.Tyrell"       "Melisandre"            "Name"                 
[31] "Osha"                  "Petyr.Baelish"         "Podrick.Payne"        
[34] "Pyat.Pree"             "Renly.Baratheon"       "Robb.Stark"           
[37] "Robert.Baratheon"      "Ros"                   "Samwell.Tarly"        
[40] "Sandor.Clegane"        "Sansa.Stark"           "Shae"                 
[43] "Stannis.Baratheon"     "Theon.Greyjoy"         "Tyrion.Lannister"     
[46] "Tywin.Lannister"       "Varys"                 "Viserys.Targaryen"    
[49] "Xaro.Xhoan.Daxos"     
Code
got_like_dislike.ig <- graph_from_data_frame(got_like_dislike)

vcount(got_like_dislike.ig)
[1] 11
Code
ecount(got_like_dislike.ig)
[1] 46
  1. Network features Are these networks weighted, directed, and bipartite? Our networks are not weighted or barparite, it is only directed
Code
is.bipartite(got_like_dislike.ig)
[1] FALSE
Code
is.directed(got_like_dislike.ig)
[1] TRUE
Code
is.weighted(got_like_dislike.ig)
[1] FALSE
  1. Network Attributes Now, using commands from either statnet or igraph, list the vertex and edge attributes.
Code
igraph::vertex_attr_names(got_like_dislike.ig)
[1] "name"
Code
igraph::edge_attr_names(got_like_dislike.ig)
 [1] "Name"                  "Lysa.Arryn"            "Petyr.Baelish"        
 [4] "Joffrey.Baratheon"     "Margaery.Tyrell"       "Renly.Baratheon"      
 [7] "Robert.Baratheon"      "Stannis.Baratheon"     "Brienne.of.Tarth"     
[10] "Bronn"                 "Gregor.Clegane"        "Sandor.Clegane"       
[13] "Xaro.Xhoan.Daxos"      "Gendry"                "Balon.Greyjoy"        
[16] "Theon.Greyjoy"         "Jaqen.H.ghar"          "Hodor"                
[19] "Khal.Drogo"            "Cersei.Lannister"      "Jaime.Lannister"      
[22] "Lancel.Lannister"      "Tyrion.Lannister"      "Tywin.Lannister"      
[25] "Maester.Luwin"         "Melisandre"            "Jeor.Mormont"         
[28] "Jorah.Mormont"         "Osha"                  "Podrick.Payne"        
[31] "Pyat.Pree"             "Grand.Maester.Pycelle" "Ros"                  
[34] "Davos.Seaworth"        "Shae"                  "Jon.Snow"             
[37] "Arya.Stark"            "Bran.Stark"            "Catelyn.Stark"        
[40] "Robb.Stark"            "Sansa.Stark"           "Daenerys.Targaryen"   
[43] "Viserys.Targaryen"     "Samwell.Tarly"         "Loras.Tyrell"         
[46] "Varys"                 "Eddard.Stark"         

Dyad and Triad Census

Now try a full dyad census. This gives us the number of dyads where the relationship is:

  • Reciprocal (mutual), or mut
  • Asymmetric (non-mutual), or asym, and
  • Absent, or null
Code
igraph::dyad.census(got_like_dislike.ig)
$mut
[1] 1

$asym
[1] 12

$null
[1] 42

Now use triad.census in order to do a triad census..

Code
igraph::triad.census(got_like_dislike.ig)
 [1] 83 32 18  1 22  1  5  0  1  0  0  2  0  0  0  0

Global and Local Transitivity or Clustering

Compute global transitivity using transitivity on igraph or gtrans on statnet and local transitivity of specific nodes of your choice, in addition to the average clustering coefficient. What is the distribution of node degree and how does it compare with the distribution of local transitivity?

Code
transitivity(got_like_dislike.ig)
[1] 0.2368421
Code
transitivity(got_like_dislike.ig, type = 'global')
[1] 0.2368421
Code
transitivity(got_like_dislike.ig, type = 'localaverage')
[1] 0.5867347

Path Length and Component Structure

Can you compute the average path length and the diameter of the network? Can you find the component structure of the network and identify the cluster membership of each node?

Code
avg_path_length = average.path.length(got_like_dislike.ig, directed=F)
avg_path_length
[1] 2.127273
Code
names(igraph::components(got_like_dislike.ig))
[1] "membership" "csize"      "no"        
Code
ncomp = igraph::components(got_like_dislike.ig)$no
ncomp
[1] 1
Code
scomp = igraph::components(got_like_dislike.ig)$csize
scomp
[1] 11

Average path distance is 2.13 with a component at size 11 diameter is at 2