The following objects are masked from 'package:stats':
decompose, spectrum
The following object is masked from 'package:base':
union
Code
library(network)
Warning: package 'network' was built under R version 4.2.3
'network' 1.18.1 (2023-01-24), part of the Statnet Project
* 'news(package="network")' for changes since last version
* 'citation("network")' for citation information
* 'https://statnet.org' for help, support, and other information
Attaching package: 'network'
The following objects are masked from 'package:igraph':
%c%, %s%, add.edges, add.vertices, delete.edges, delete.vertices,
get.edge.attribute, get.edges, get.vertex.attribute, is.bipartite,
is.directed, list.edge.attributes, list.vertex.attributes,
set.edge.attribute, set.vertex.attribute
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
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.
Code
# Number of vertices in got_marriages network:vcount(got_marriages.ig)
[1] 20
Code
# Number of edges in got_marriages network:ecount(got_marriages.ig)
[1] 255
Code
# Bipartite or single mode network verification in got_marriages network:is_bipartite(got_marriages.ig)
[1] FALSE
Code
# Directed or undirected edges verification in got_marriages networkis_directed(got_marriages.ig)
[1] TRUE
Code
# Weighted or unweighted edges verification in got_marriages networkis_weighted(got_marriages.ig)
[1] FALSE
Code
# Is Connected verification in got_marriages networkis_connected(got_marriages.ig)
[1] TRUE
Code
# Degree calculation in got_marriages networkdegree =degree(got_marriages.ig)# Indegreedegree(got_marriages.ig, mode ='out')
# Global Transitivity calculation in got_marriages networktransitivity(got_marriages.ig, type ="global")
[1] 0.4411765
Code
# Local Average Transitivity calculation in got_marriages networktransitivity(got_marriages.ig, type ="localaverage")
[1] 0.5478074
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
# BetweennessV(got_marriages.ig)$betweenness <-igraph::betweenness(got_marriages.ig)# closenessV(got_marriages.ig)$closeness <-igraph::closeness(got_marriages.ig)# eigen_centralityV(got_marriages.ig)$eigen_centrality <-igraph::eigen_centrality(got_marriages.ig)$vector# Compute the Distribution eigencentralityeigen_table <-table(V(got_marriages.ig)$eigen_centrality)print(eigen_table)
---title: "Week 4 Challenge"author: "Akhilesh Kumar"description: "Centrality of a Network"date: "04/20/2023"format: html: toc: true code-fold: true code-copy: true code-tools: true# editor: visualcategories: - challenge_4 - instructions---```{r setup, include=FALSE, warnings=FALSE}knitr::opts_chunk$set(echo =TRUE)``````{r}library(igraph)library(network)```## Reading Data```{r}got_marriages <-read.csv("_data/got/got_marriages.csv")head(got_marriages)got_marriages.ig <-graph_from_data_frame(got_marriages, directed =TRUE)```## 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.```{r}# Number of vertices in got_marriages network:vcount(got_marriages.ig)# Number of edges in got_marriages network:ecount(got_marriages.ig)# Bipartite or single mode network verification in got_marriages network:is_bipartite(got_marriages.ig)# Directed or undirected edges verification in got_marriages networkis_directed(got_marriages.ig)# Weighted or unweighted edges verification in got_marriages networkis_weighted(got_marriages.ig)# Is Connected verification in got_marriages networkis_connected(got_marriages.ig)# Degree calculation in got_marriages networkdegree =degree(got_marriages.ig)# Indegreedegree(got_marriages.ig, mode ='out')# Local Transitivity calculation in got_marriages networktransitivity(got_marriages.ig, type ="local")# Global Transitivity calculation in got_marriages networktransitivity(got_marriages.ig, type ="global")# Local Average Transitivity calculation in got_marriages networktransitivity(got_marriages.ig, type ="localaverage")```## 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}# BetweennessV(got_marriages.ig)$betweenness <-igraph::betweenness(got_marriages.ig)# closenessV(got_marriages.ig)$closeness <-igraph::closeness(got_marriages.ig)# eigen_centralityV(got_marriages.ig)$eigen_centrality <-igraph::eigen_centrality(got_marriages.ig)$vector# Compute the Distribution eigencentralityeigen_table <-table(V(got_marriages.ig)$eigen_centrality)print(eigen_table)# Compute the Distribution closenessclose_table <-table(V(got_marriages.ig)$closeness)print(close_table)# Compute the Distribution of betweennessbetween_table <-table(V(got_marriages.ig)$betweenness)print(between_table)```