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
got_distances
# A tibble: 200 × 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
7 Westerlands Kayce Faircastle 480 raven <NA>
8 Westerlands Faircastle the Crag 115 Boat Island
9 Westerlands the Crag Ashemark 85 land <NA>
10 Westerlands Ashemark Casterly Rock 170 land <NA>
# … with 190 more rows
This network has 200 edges and 103 vertices. The vertex attribute is ‘name’ and edge attributes are “To”, “Miles”, “Mode”, and “Notes”. It is directed, not bipartite, and not weighted. Dyad census reveals that there are 0 mutual, 93 asymmetric, and 5160 null relationships in this network of distances between regions in the GOT universe
Code
# number of componentsigraph::components(got_distances.ig)$no
[1] 10
Code
# size of componentsigraph::components(got_distances.ig)$csize
[1] 9 12 7 13 6 10 12 13 1 20
There are 10 components, the smallest of which is 1 node and largest is 20.
Density
Code
# network densitygraph.density(got_distances.ig)
[1] 0.01903674
Code
# density without loopsgraph.density(got_distances.ig, loops=TRUE)
[1] 0.01885192
The density of this network, a global measure, is 0.01903674 which suggests that it isn’t very dense. Without accounting for loops, the density value decreases to 0.01885192.
Analyzing the average network degree, a vast majority of the nodes have an average degree of 1 or 2, which supports the previous finding of the network not being very dense.
Code
# average network degreeigraph::degree(got_distances.ig)
Westerlands Reach
14 19
Riverlands Vale
18 19
Crownlands Stormlands
13 13
Dorne North
16 26
Iron Islands Essos
10 57
Casterly Rock Deep Den
5 1
Kayce Faircastle
1 1
the Crag Ashemark
1 2
Lannisport Crakehall
2 1
Old Oak Highgarden
1 5
Oldtown Blackcrown
2 2
Three Towers Mouth of the Mander River
1 1
Golden Grove Cider Hall
1 2
Longtable Harroway
2 7
Seagard Riverrun
3 3
Harrenhal Saltpans
2 1
Maidenpool Border
2 1
the Bloody Gate Wickenden
1 2
Gulltown Runestone
1 2
Old Anchor Longbow Hall
2 2
Snakewoods Heart’s Home
3 1
the Sisters Pebble Island
2 1
the Paps King’s Landing
1 7
Duskendale Rook’s Rest
2 1
Sharp Point Dragonstone
1 2
Wendwater Bronze Gate
1 1
Storm’s End Summerhall
4 1
Blackhaven Rain House
1 1
Mistwood Weeping Tower
2 1
Stonehelm Wyl
1 1
Yronwood the Tor
1 1
Godsgrace Saltshore
3 1
Vaith Hellholt
1 3
Skyreach Moat Cailin
1 2
Cerwyn Greywater Watch
1 1
Flint’s Finger White Harbor
1 2
Ramsgate Widow’s Watch
2 1
Karhold Dreadfort
2 2
Winterfell Deepwood Motte
5 2
Barrowton the Shield Islands
5 1
the Arbor the Southern Dornish Coastline
1 1
Lemonwood Sunspear
2 1
Tyrosh Pentos
7 2
Braavos Lorath
6 1
Lys Volantis
2 5
New Ghis Astapor
9 2
Yunkai Dagger Lake
2 2
the Stepstones Myr
1 3
Selhorys Qohor
2 1
Norvos Vaes Dothrak
2 4
Mantarys Bhorash
2 1
Meereen
3
Creating a data frame of the nodes in the network and finding out the in-degree and out-degree values of each:
name degree indegree outdegree
Length:103 Min. : 0.000 Min. :0.000 Min. : 0.000
Class :character 1st Qu.: 1.000 1st Qu.:1.000 1st Qu.: 0.000
Mode :character Median : 2.000 Median :1.000 Median : 0.000
Mean : 3.786 Mean :1.893 Mean : 1.893
3rd Qu.: 3.000 3rd Qu.:2.000 3rd Qu.: 0.000
Max. :57.000 Max. :9.000 Max. :57.000
Random Network
Creating a random (Erdos-Renyi) network with the same number of nodes and edges as the GOT distances network:
Code
erdos_renyi.ig <-sample_gnm(103, 200, directed =TRUE, loops =FALSE)# density of random networkgraph.density(erdos_renyi.ig)
[1] 0.01903674
Code
# dyad census of random networkigraph::dyad.census(erdos_renyi.ig)
$mut
[1] 2
$asym
[1] 196
$null
[1] 5055
Code
# triad census of random networkigraph::triad.census(erdos_renyi.ig)
degree indegree outdegree
Min. : 0.000 Min. :0.000 Min. :0.000
1st Qu.: 3.000 1st Qu.:1.000 1st Qu.:1.000
Median : 4.000 Median :2.000 Median :2.000
Mean : 3.883 Mean :1.942 Mean :1.942
3rd Qu.: 5.000 3rd Qu.:3.000 3rd Qu.:3.000
Max. :10.000 Max. :7.000 Max. :6.000
Comparing the random network statistics with those of the got_distances.ig, the density values are comparable, and so are the values from the dyad census. The triad census values for the random network are higher. The in-degree values for the distances network are all 0. At the same time, its values for out-degree and degree are much higher than those in the random network.
Source Code
---title: "Week 3 Challenge"author: "Ananya Pujary"description: "Degree and Density of a Network"date: "03/06/2023"format: html: toc: true code-fold: true code-copy: true code-tools: true# editor: visualcategories: - challenge_3 - Ananya Pujary # - railroads # - faostat # - wildbirds---```{r}#| label: setup#| include: falselibrary(igraph)library(network)library(readr)library(dplyr)```## DegreeI've chosen to work with the `got_distances.csv` dataset that provides information about the distances between regions in the GOT universe.```{r}got_distances <-read_csv("../posts/_data/got/got_distances.csv")got_distancesgot_distances.ig <-graph_from_data_frame(got_distances, directed =TRUE)``````{r}# number of edgesecount(got_distances.ig)# number of verticesvcount(got_distances.ig)# vertex and edge attributesvertex_attr_names(got_distances.ig)edge_attr_names(got_distances.ig)# network featuresis_directed(got_distances.ig)is_bipartite(got_distances.ig)is_weighted(got_distances.ig)# dyad censusigraph::dyad.census(got_distances.ig)# triad censustriad_census(got_distances.ig)```This network has 200 edges and 103 vertices. The vertex attribute is 'name' and edge attributes are "To", "Miles", "Mode", and "Notes". It is directed, not bipartite, and not weighted. Dyad census reveals that there are 0 mutual, 93 asymmetric, and 5160 null relationships in this network of distances between regions in the GOT universe```{r}# number of componentsigraph::components(got_distances.ig)$no# size of componentsigraph::components(got_distances.ig)$csize ```There are 10 components, the smallest of which is 1 node and largest is 20.## Density```{r}# network densitygraph.density(got_distances.ig)# density without loopsgraph.density(got_distances.ig, loops=TRUE)```The density of this network, a global measure, is 0.01903674 which suggests that it isn't very dense. Without accounting for loops, the density value decreases to 0.01885192.Analyzing the average network degree, a vast majority of the nodes have an average degree of 1 or 2, which supports the previous finding of the network not being very dense.```{r}# average network degreeigraph::degree(got_distances.ig)```Creating a data frame of the nodes in the network and finding out the in-degree and out-degree values of each:```{r}nodes_ig<-data.frame(name=V(got_distances.ig)$name, degree=igraph::degree(got_distances.ig,loops=FALSE))nodes_ig<-nodes_ig %>%mutate(indegree=igraph::degree(got_distances.ig, mode="in", loops=FALSE),outdegree=igraph::degree(got_distances.ig, mode="out", loops=FALSE))head(nodes_ig)``````{r}summary(nodes_ig)```## Random NetworkCreating a random (Erdos-Renyi) network with the same number of nodes and edges as the GOT distances network:```{r}erdos_renyi.ig <-sample_gnm(103, 200, directed =TRUE, loops =FALSE)# density of random networkgraph.density(erdos_renyi.ig)# dyad census of random networkigraph::dyad.census(erdos_renyi.ig)# triad census of random networkigraph::triad.census(erdos_renyi.ig)```The density of the random graph is 0.01903674. It has 1 mutual, 198 asymmetric, and 5054 null relationships.Now, looking at the degree distributions in this random network:```{r}nodes_rand<-data.frame(degree=igraph::degree(erdos_renyi.ig))nodes_rand<-nodes_rand %>%mutate(indegree=igraph::degree(erdos_renyi.ig, mode="in", loops=FALSE),outdegree=igraph::degree(erdos_renyi.ig, mode="out", loops=FALSE))head(nodes_rand)``````{r}summary(nodes_rand)```Comparing the random network statistics with those of the `got_distances.ig`, the density values are comparable, and so are the values from the dyad census. The triad census values for the random network are higher. The in-degree values for the distances network are all 0. At the same time, its values for out-degree and degree are much higher than those in the random network.