── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.2 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.2 ✔ tibble 3.2.1
✔ lubridate 1.9.2 ✔ tidyr 1.3.0
✔ purrr 1.0.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Code
library(igraph)
Attaching package: 'igraph'
The following objects are masked from 'package:lubridate':
%--%, union
The following objects are masked from 'package:dplyr':
as_data_frame, groups, union
The following objects are masked from 'package:purrr':
compose, simplify
The following object is masked from 'package:tidyr':
crossing
The following object is masked from 'package:tibble':
as_data_frame
The following objects are masked from 'package:stats':
decompose, spectrum
The following object is masked from 'package:base':
union
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
List and inspect List the objects to make sure the datafiles are working properly.
Network Size What is the size of the network? You may use vcount and ecount.
Network features Are these networks weighted, directed, and bipartite?
Network Attributes Now, using commands from either statnet or igraph, list the vertex and edge attributes.
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
Now use triad.census in order to do a triad census.
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?
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
# find got marriages data framegot_marriages <-read.csv("C:/Users/18639/Social_Networks_Spring_2023/posts/_data/got/got_marriages.csv")
From To Type Notes Generation
1 Targaryen Stark Married R+L=J Current
2 Baratheon Martell Engaged died Current
3 Baratheon Stark Engaged broken Current
4 Martell Essos Married Current
5 Martell Reach Affair Current
6 Martell Essos Affair Current
# Performa a dyad census of the networkdyad.census(graph)
$mut
[1] 3
$asym
[1] 57
$null
[1] 130
Code
# Perform a triad census on the networktriad.census(graph)
[1] 408 227 217 110 44 47 9 18 50 1 0 3 5 1 0 0
Code
# Compute the transitivity of the netwroktransitivity(graph)
[1] 0.4411765
Code
# Find the average path lengthaverage.path.length(graph)
[1] 1.86875
Code
# Find the width of the networkdiameter(graph)
[1] 4
Source Code
---title: "Week 2 Challenge Instructions"author: "Hannah Rosenbaum"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: visualcategories: - challenge_2 - instructions # - railroads # - faostat # - wildbirds---```{r}#| label: setup#| include: false#| ``````{r}library(tidyverse)library(igraph)```## Challenge OverviewDescribe 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 MembershipBe sure to both provide the relevant statistics calculated in `R`, as well as your own interpretation of these statistics.## Describe the Network Data1. *List and inspect* List the objects to make sure the datafiles are working properly.2. *Network Size* What is the size of the network? You may use `vcount` and `ecount`.3. *Network features* Are these networks weighted, directed, and bipartite?4. *Network Attributes* Now, using commands from either `statnet` or `igraph`, list the vertex and edge attributes.## Dyad and Triad CensusNow 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`Now use `triad.census` in order to do a triad census.## Global and Local Transitivity or ClusteringCompute 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?## 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}# find got marriages data framegot_marriages <-read.csv("C:/Users/18639/Social_Networks_Spring_2023/posts/_data/got/got_marriages.csv")``````{r}graph <-graph_from_edgelist(as.matrix(got_marriages[, c("From", "To")]))# List/display datahead(got_marriages)# Show network sizevcount(graph)ecount(graph)# Is the graph bipartiteis_bipartite(graph)# Is teh graph weightedis_weighted(graph)# Is the graph directedis_directed(graph)# Listing vertex attributesvertex_attr_names(graph)# Listing edge attributesedge_attr_names(graph)``````{r}# Performa a dyad census of the networkdyad.census(graph)# Perform a triad census on the networktriad.census(graph)``````{r}# Compute the transitivity of the netwroktransitivity(graph)``````{r}# Find the average path lengthaverage.path.length(graph)# Find the width of the networkdiameter(graph)```