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.2.3
Rows: 200 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): Region From, From, To, Mode, Notes
dbl (1): Miles
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Code
head(got_distances)
# A tibble: 6 × 6
`Region From` From To Miles Mode Notes
<chr> <chr> <chr> <dbl> <chr> <chr>
1 Westerlands Casterly Rock the Golden Tooth 240 land <NA>
2 Westerlands Casterly Rock Lannisport 40 land <NA>
3 Westerlands Casterly Rock Kayce 100 land <NA>
4 Westerlands Casterly Rock Kayce 12 water <NA>
5 Westerlands Casterly Rock Deep Den 240 land Goldroad
6 Westerlands Deep Den King’s Landing 590 land Goldroad
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 datasetnet <-graph.data.frame(got_distances, directed =FALSE)# Basic structure of the networkedges <-ecount(net)vertices <-vcount(net)# Dyad and triad censusdyads <-dyad_census(net)triads <-triad_census(net)# Create the nodes data frame with local attributesnodes <-data.frame(vertex =V(net)$name, # Assuming the vertices have a 'name' attributedegree =degree(net),transitivity =transitivity(net, type ="local"))
Code
# Print the basic network structurecat("Number of edges:", edges, "\n")
vertex degree
Westerlands Westerlands 14
Reach Reach 19
Riverlands Riverlands 18
Vale Vale 19
Crownlands Crownlands 13
Stormlands Stormlands 13
Dorne Dorne 16
North North 26
Iron Islands Iron Islands 10
Essos Essos 57
Casterly Rock Casterly Rock 5
Deep Den Deep Den 1
Kayce Kayce 1
Faircastle Faircastle 1
the Crag the Crag 1
Ashemark Ashemark 2
Lannisport Lannisport 2
Crakehall Crakehall 1
Old Oak Old Oak 1
Highgarden Highgarden 5
Oldtown Oldtown 2
Blackcrown Blackcrown 2
Three Towers Three Towers 1
Mouth of the Mander River Mouth of the Mander River 1
Golden Grove Golden Grove 1
Cider Hall Cider Hall 2
Longtable Longtable 2
Harroway Harroway 7
Seagard Seagard 3
Riverrun Riverrun 3
Harrenhal Harrenhal 2
Saltpans Saltpans 1
Maidenpool Maidenpool 2
Border Border 1
the Bloody Gate the Bloody Gate 1
Wickenden Wickenden 2
Gulltown Gulltown 1
Runestone Runestone 2
Old Anchor Old Anchor 2
Longbow Hall Longbow Hall 2
Snakewoods Snakewoods 3
Heart’s Home Heart’s Home 1
the Sisters the Sisters 2
Pebble Island Pebble Island 1
the Paps the Paps 1
King’s Landing King’s Landing 7
Duskendale Duskendale 2
Rook’s Rest Rook’s Rest 1
Sharp Point Sharp Point 1
Dragonstone Dragonstone 2
Wendwater Wendwater 1
Bronze Gate Bronze Gate 1
Storm’s End Storm’s End 4
Summerhall Summerhall 1
Blackhaven Blackhaven 1
Rain House Rain House 1
Mistwood Mistwood 2
Weeping Tower Weeping Tower 1
Stonehelm Stonehelm 1
Wyl Wyl 1
Yronwood Yronwood 1
the Tor the Tor 1
Godsgrace Godsgrace 3
Saltshore Saltshore 1
Vaith Vaith 1
Hellholt Hellholt 3
Skyreach Skyreach 1
Moat Cailin Moat Cailin 2
Cerwyn Cerwyn 1
Greywater Watch Greywater Watch 1
Flint’s Finger Flint’s Finger 1
White Harbor White Harbor 2
Ramsgate Ramsgate 2
Widow’s Watch Widow’s Watch 1
Karhold Karhold 2
Dreadfort Dreadfort 2
Winterfell Winterfell 5
Deepwood Motte Deepwood Motte 2
Barrowton Barrowton 5
the Shield Islands the Shield Islands 1
the Arbor the Arbor 1
the Southern Dornish Coastline the Southern Dornish Coastline 1
Lemonwood Lemonwood 2
Sunspear Sunspear 1
Tyrosh Tyrosh 7
Pentos Pentos 2
Braavos Braavos 6
Lorath Lorath 1
Lys Lys 2
Volantis Volantis 5
New Ghis New Ghis 9
Astapor Astapor 2
Yunkai Yunkai 2
Dagger Lake Dagger Lake 2
the Stepstones the Stepstones 1
Myr Myr 3
Selhorys Selhorys 2
Qohor Qohor 1
Norvos Norvos 2
Vaes Dothrak Vaes Dothrak 4
Mantarys Mantarys 2
Bhorash Bhorash 1
Meereen Meereen 3
transitivity
Westerlands 0
Reach 0
Riverlands 0
Vale 0
Crownlands 0
Stormlands 0
Dorne 0
North 0
Iron Islands NaN
Essos 0
Casterly Rock NaN
Deep Den NaN
Kayce NaN
Faircastle NaN
the Crag NaN
Ashemark NaN
Lannisport NaN
Crakehall NaN
Old Oak NaN
Highgarden NaN
Oldtown NaN
Blackcrown NaN
Three Towers NaN
Mouth of the Mander River NaN
Golden Grove NaN
Cider Hall NaN
Longtable NaN
Harroway NaN
Seagard NaN
Riverrun NaN
Harrenhal NaN
Saltpans NaN
Maidenpool NaN
Border NaN
the Bloody Gate NaN
Wickenden NaN
Gulltown NaN
Runestone NaN
Old Anchor NaN
Longbow Hall NaN
Snakewoods NaN
Heart’s Home NaN
the Sisters NaN
Pebble Island NaN
the Paps NaN
King’s Landing NaN
Duskendale NaN
Rook’s Rest NaN
Sharp Point NaN
Dragonstone NaN
Wendwater NaN
Bronze Gate NaN
Storm’s End NaN
Summerhall NaN
Blackhaven NaN
Rain House NaN
Mistwood NaN
Weeping Tower NaN
Stonehelm NaN
Wyl NaN
Yronwood NaN
the Tor NaN
Godsgrace NaN
Saltshore NaN
Vaith NaN
Hellholt NaN
Skyreach NaN
Moat Cailin NaN
Cerwyn NaN
Greywater Watch NaN
Flint’s Finger NaN
White Harbor NaN
Ramsgate NaN
Widow’s Watch NaN
Karhold NaN
Dreadfort NaN
Winterfell NaN
Deepwood Motte NaN
Barrowton NaN
the Shield Islands NaN
the Arbor NaN
the Southern Dornish Coastline NaN
Lemonwood NaN
Sunspear NaN
Tyrosh NaN
Pentos NaN
Braavos NaN
Lorath NaN
Lys NaN
Volantis NaN
New Ghis NaN
Astapor NaN
Yunkai NaN
Dagger Lake NaN
the Stepstones NaN
Myr NaN
Selhorys NaN
Qohor NaN
Norvos NaN
Vaes Dothrak NaN
Mantarys NaN
Bhorash NaN
Meereen NaN
# Compute the distribution of one centrality measure (e.g., eigencentrality)eigen_dist <-table(nodes$eigen)# Print the distribution of eigencentralityprint(eigen_dist)
< table of extent 0 >
Source Code
---title: "Week 4 Challenge"author: "Niharika Pola"description: "Centrality of a Network"date: "03/10/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_distances <-read_csv("_data/got/got_distances.csv")head(got_distances)``````{r, warning=FALSE}# Load the required packagelibrary(igraph)# Create the network from the datasetnet <-graph.data.frame(got_distances, directed =FALSE)# Basic structure of the networkedges <-ecount(net)vertices <-vcount(net)# Dyad and triad censusdyads <-dyad_census(net)triads <-triad_census(net)# Create the nodes data frame with local attributesnodes <-data.frame(vertex =V(net)$name, # Assuming the vertices have a 'name' attributedegree =degree(net),transitivity =transitivity(net, 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_net <-centr_degree(net, loops =FALSE, mode ="in")in_netout_net <-centr_degree(net, loops =FALSE, mode ="out")out_netnet_total <-centr_degree(net, loops =FALSE, mode ="total")net_total``````{r}eigen <-eigen_centrality(net)$vectorbetweeness <- igraph::betweenness(net, directed = F)close <- igraph::closeness(net, mode ="out")``````{r}# Compute the distribution of one centrality measure (e.g., eigencentrality)eigen_dist <-table(nodes$eigen)# Print the distribution of eigencentralityprint(eigen_dist)```