Code
ls()
character(0)
Code
<- read.csv('_data/got/got_like_dislike.csv')
got_like_dislike
view(got_like_dislike)
Amer Abuhasan
February 22, 2023
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:
Be sure to both provide the relevant statistics calculated in R
, as well as your own interpretation of these statistics.
character(0)
vcount
and ecount
. #the size of the network is 11 vertices with 46 edges [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"
[1] 11
[1] 46
[1] FALSE
[1] TRUE
[1] FALSE
statnet
or igraph
, list the vertex and edge attributes.[1] "name"
[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"
Now try a full dyad census. This gives us the number of dyads where the relationship is:
mut
asym
, andnull
Now use triad.census
in order to do a triad census..
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?
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?
[1] 2.127273
[1] "membership" "csize" "no"
[1] 1
[1] 11
Average path distance is 2.13 with a component at size 11 diameter is at 2
---
title: "Week 2 Challenge Instructions"
author: "Amer Abuhasan "
description: "Describing the Basic Structure of a Network"
date: "02/22/2023"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
# editor: visual
categories:
- challenge_2
- instructions
# - railroads
# - faostat
# - wildbirds
---
```{r}
#| label: setup
#| include: false
library(tidyverse)
library(readr)
library(igraph)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE,
message=FALSE)
```
## 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.
```{r}
ls()
got_like_dislike <- read.csv('_data/got/got_like_dislike.csv')
view(got_like_dislike)
```
2. *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
```{r}
ls(got_like_dislike)
got_like_dislike.ig <- graph_from_data_frame(got_like_dislike)
vcount(got_like_dislike.ig)
ecount(got_like_dislike.ig)
```
3. *Network features* Are these networks weighted, directed, and bipartite?
Our networks are not weighted or barparite, it is only directed
```{r}
is.bipartite(got_like_dislike.ig)
is.directed(got_like_dislike.ig)
is.weighted(got_like_dislike.ig)
```
4. *Network Attributes* Now, using commands from either `statnet` or `igraph`, list the vertex and edge attributes.
```{r}
igraph::vertex_attr_names(got_like_dislike.ig)
igraph::edge_attr_names(got_like_dislike.ig)
```
## 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`
```{r}
igraph::dyad.census(got_like_dislike.ig)
```
Now use `triad.census` in order to do a triad census..
```{r}
igraph::triad.census(got_like_dislike.ig)
```
## 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?
```{r}
transitivity(got_like_dislike.ig)
transitivity(got_like_dislike.ig, type = 'global')
transitivity(got_like_dislike.ig, type = 'localaverage')
```
## 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?
```{r}
avg_path_length = average.path.length(got_like_dislike.ig, directed=F)
avg_path_length
names(igraph::components(got_like_dislike.ig))
ncomp = igraph::components(got_like_dislike.ig)$no
ncomp
scomp = igraph::components(got_like_dislike.ig)$csize
scomp
```
Average path distance is 2.13 with a component at size 11
diameter is at 2