Describe the many measures of centrality of at least one network of your choice.
Describe the Network Data
If you have not done it before, always start by evaluating the basic structure of the network (number of edges and vertices, dyad and triad census, etc.). Create a data frame `nodes` with the corresponding local attributes such as degree or local transitivity.
Centrality
Compute at least one measure of centrality for each node, adding them as attributes to `nodes` in the form of extra columns: eigencentrality, betweenness, closeness, etc. Compute the distribution of at least one of those measures. What do we learn from comparing these measures of centrality with an equivalent random network (i.e. with the same number of edges and vertices)?
Code
library(readr)
Warning: package 'readr' was built under R version 4.1.3
Rows: 255 Columns: 5
-- Column specification --------------------------------------------------------
Delimiter: ","
chr (5): From, To, Type, Notes, Generation
i Use `spec()` to retrieve the full column specification for this data.
i Specify the column types or set `show_col_types = FALSE` to quiet this message.
Code
head(got_marriages)
# A tibble: 6 x 5
From To Type Notes Generation
<chr> <chr> <chr> <chr> <chr>
1 Targaryen Stark Married R+L=J Current
2 Baratheon Martell Engaged died Current
3 Baratheon Stark Engaged broken Current
4 Martell Essos Married <NA> Current
5 Martell Reach Affair <NA> Current
6 Martell Essos Affair <NA> Current
Code
# Load the required packagelibrary(igraph)
Attaching package: 'igraph'
The following objects are masked from 'package:stats':
decompose, spectrum
The following object is masked from 'package:base':
union
Code
# Create the network from the datasetnetw <-graph.data.frame(got_marriages, directed =FALSE)# Basic structure of the networkedges <-ecount(netw)vertices <-vcount(netw)# Dyad and triad censusdyads <-dyad_census(netw)triads <-triad_census(netw)# Create the nodes data frame with local attributesnodes <-data.frame(vertex =V(netw)$name, # Assuming the vertices have a 'name' attributedegree =degree(netw),transitivity =transitivity(netw, type ="local"))
Code
# Print the basic network structurecat("Number of edges:", edges, "\n")
# Compute the distribution of one centrality measure (e.g., eigencentrality)eigen_distance <-table(nodes$eigen)# Print the distribution of eigencentralityprint(eigen_distance)
< table of extent 0 >
Source Code
---title: "Week_4_Challenge"author: "Rahul Gundeti"description: "Centrality of a Network"date: "03/15/2023"format: html: toc: true code-fold: true code-copy: true code-tools: true# editor: visualcategories: - challenge_4 - instructions # - railroads # - faostat # - wildbirds---```{r}#| label: setup#| include: false```#### Challenge OverviewDescribe the many measures of centrality of at least one network of your choice.##### Describe the Network DataIf you have not done it before, always start by evaluating the basic structure of the network (number of edges and vertices, dyad and triad census, etc.). Create a data frame \`nodes\` with the corresponding local attributes such as degree or local transitivity.##### CentralityCompute at least one measure of centrality for each node, adding them as attributes to \`nodes\` in the form of extra columns: eigencentrality, betweenness, closeness, etc. Compute the distribution of at least one of those measures. What do we learn from comparing these measures of centrality with an equivalent random network (i.e. with the same number of edges and vertices)?```{r}library(readr)got_marriages <-read_csv("_data/got/got_marriages.csv")head(got_marriages)``````{r, warning=FALSE}# Load the required packagelibrary(igraph)# Create the network from the datasetnetw <-graph.data.frame(got_marriages, directed =FALSE)# Basic structure of the networkedges <-ecount(netw)vertices <-vcount(netw)# Dyad and triad censusdyads <-dyad_census(netw)triads <-triad_census(netw)# Create the nodes data frame with local attributesnodes <-data.frame(vertex =V(netw)$name, # Assuming the vertices have a 'name' attributedegree =degree(netw),transitivity =transitivity(netw, type ="local"))``````{r}# Print the basic network structurecat("Number of edges:", edges, "\n")cat("Number of vertices:", vertices, "\n")print(dyads)print(triads)# Print the nodes data frameprint(nodes)``````{r}in_netw <-centr_degree(netw, loops =FALSE, mode ="in")in_netwout_netw <-centr_degree(netw, loops =FALSE, mode ="out")out_netwnetw_total <-centr_degree(netw, loops =FALSE, mode ="total")netw_total``````{r}eigen <-eigen_centrality(netw)$vectorbetweeness <- igraph::betweenness(netw, directed = F)close <- igraph::closeness(netw, mode ="out")``````{r}# Compute the distribution of one centrality measure (e.g., eigencentrality)eigen_distance <-table(nodes$eigen)# Print the distribution of eigencentralityprint(eigen_distance)```