Week 4 Challenge Instructions

challenge_4
instructions
Centrality of a Network
Author

Yakub Rabiuhteen

Published

March 6, 2023

Challenge Overview

Describe the many measures of centrality of at least one network of your choice.

I have decided to use the Florentine Dataset.

Code
library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.1.3
-- Attaching packages --------------------------------------- tidyverse 1.3.2 --
v ggplot2 3.3.5     v purrr   0.3.4
v tibble  3.1.6     v dplyr   1.0.9
v tidyr   1.2.0     v stringr 1.4.0
v readr   2.1.2     v forcats 0.5.1
Warning: package 'ggplot2' was built under R version 4.1.3
Warning: package 'tibble' was built under R version 4.1.3
Warning: package 'tidyr' was built under R version 4.1.3
Warning: package 'readr' was built under R version 4.1.3
Warning: package 'purrr' was built under R version 4.1.3
Warning: package 'dplyr' was built under R version 4.1.3
Warning: package 'stringr' was built under R version 4.1.3
Warning: package 'forcats' was built under R version 4.1.3
-- Conflicts ------------------------------------------ tidyverse_conflicts() --
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
Code
library(igraph)
Warning: package 'igraph' was built under R version 4.1.3

Attaching package: 'igraph'

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
Code
library(sna)
Warning: package 'sna' was built under R version 4.1.3
Loading required package: statnet.common
Warning: package 'statnet.common' was built under R version 4.1.3

Attaching package: 'statnet.common'

The following objects are masked from 'package:base':

    attr, order

Loading required package: network
Warning: package 'network' was built under R version 4.1.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

sna: Tools for Social Network Analysis
Version 2.7-1 created on 2023-01-24.
copyright (c) 2005, Carter T. Butts, University of California-Irvine
 For citation information, type citation("sna").
 Type help(package="sna") to get started.


Attaching package: 'sna'

The following objects are masked from 'package:igraph':

    betweenness, bonpow, closeness, components, degree, dyad.census,
    evcent, hierarchy, is.connected, neighborhood, triad.census
Code
library(network)
library(statnet)
Warning: package 'statnet' was built under R version 4.1.3
Loading required package: tergm
Warning: package 'tergm' was built under R version 4.1.3
Loading required package: ergm
Warning: package 'ergm' was built under R version 4.1.3

'ergm' 4.4.0 (2023-01-26), part of the Statnet Project
* 'news(package="ergm")' for changes since last version
* 'citation("ergm")' for citation information
* 'https://statnet.org' for help, support, and other information

'ergm' 4 is a major update that introduces some backwards-incompatible
changes. Please type 'news(package="ergm")' for a list of major
changes.


Attaching package: 'ergm'

The following object is masked from 'package:statnet.common':

    snctrl

Loading required package: networkDynamic
Warning: package 'networkDynamic' was built under R version 4.1.3

'networkDynamic' 0.11.3 (2023-02-15), part of the Statnet Project
* 'news(package="networkDynamic")' for changes since last version
* 'citation("networkDynamic")' for citation information
* 'https://statnet.org' for help, support, and other information

Registered S3 method overwritten by 'tergm':
  method                   from
  simulate_formula.network ergm

'tergm' 4.1.1 (2022-11-07), part of the Statnet Project
* 'news(package="tergm")' for changes since last version
* 'citation("tergm")' for citation information
* 'https://statnet.org' for help, support, and other information


Attaching package: 'tergm'

The following object is masked from 'package:ergm':

    snctrl

The following object is masked from 'package:statnet.common':

    snctrl

Loading required package: ergm.count
Warning: package 'ergm.count' was built under R version 4.1.3

'ergm.count' 4.1.1 (2022-05-24), part of the Statnet Project
* 'news(package="ergm.count")' for changes since last version
* 'citation("ergm.count")' for citation information
* 'https://statnet.org' for help, support, and other information

Loading required package: tsna
Warning: package 'tsna' was built under R version 4.1.3

'statnet' 2019.6 (2019-06-13), part of the Statnet Project
* 'news(package="statnet")' for changes since last version
* 'citation("statnet")' for citation information
* 'https://statnet.org' for help, support, and other information

unable to reach CRAN
Code
data(flo)

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
flo_net <- network(flo, directed = FALSE)
Code
network(flo_net, directed = FALSE)
 Network attributes:
  vertices = 16 
  directed = FALSE 
  hyper = FALSE 
  loops = FALSE 
  multiple = FALSE 
  bipartite = FALSE 
  total edges= 20 
    missing edges= 0 
    non-missing edges= 20 

 Vertex attribute names: 
    vertex.names 

No edge attributes

Network attributes: vertices = 16 directed = FALSE hyper = FALSE loops = FALSE multiple = FALSE bipartite = FALSE total edges= 20 missing edges= 0 non-missing edges= 20

There are 16 actors and 20 ties in the network.

It is not directed or a bipariate network.

Code
vertex_names <- network.vertex.names(flo_net)

[1] “Acciaiuoli” “Albizzi” “Barbadori” “Bischeri” “Castellani” “Ginori” “Guadagni” “Lamberteschi” “Medici”
[10] “Pazzi” “Peruzzi” “Pucci” “Ridolfi” “Salviati” “Strozzi” “Tornabuoni”

Code
network.vertex.names(flo_net) <- network.vertex.names(flo_net)

use igraph to plot the network

Code
florentine_igraph <- graph_from_data_frame(flo_net, directed = FALSE)
Code
plot(florentine_igraph, vertex.label = vertex_names)

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
# Compute Indegree Measures
totdegree <- igraph::degree(florentine_igraph)
indegree <- igraph::degree(florentine_igraph, mode = "in", loops = FALSE)
outdegree <- igraph::degree(florentine_igraph, mode = "out", loops = FALSE)
globtrans <- igraph::transitivity(florentine_igraph, type = "global")
avgtrans <- igraph::transitivity(florentine_igraph, type = "average")
#Compute Centerality Measures
eigencentrality <- igraph::eigen_centrality(florentine_igraph)$vector
betweenness <- igraph::betweenness(florentine_igraph)
closeness <- igraph::closeness(florentine_igraph)
#Add Centerality Atribbutes to the nodes
florentine_igraph_nodes$totdegree <- totdegree
Error in florentine_igraph_nodes$totdegree <- totdegree: object 'florentine_igraph_nodes' not found
Code
florentine_igraph_nodes$indegree <- indegree
Error in florentine_igraph_nodes$indegree <- indegree: object 'florentine_igraph_nodes' not found
Code
florentine_igraph_nodes$outdegree <- outdegree
Error in florentine_igraph_nodes$outdegree <- outdegree: object 'florentine_igraph_nodes' not found
Code
florentine_igraph_nodes$globtrans <- globtrans
Error in florentine_igraph_nodes$globtrans <- globtrans: object 'florentine_igraph_nodes' not found
Code
florentine_igraph_nodes$avgtrans <- avgtrans
Error in florentine_igraph_nodes$avgtrans <- avgtrans: object 'florentine_igraph_nodes' not found
Code
florentine_igraph_nodes$eigencentrality <- eigencentrality
Error in florentine_igraph_nodes$eigencentrality <- eigencentrality: object 'florentine_igraph_nodes' not found
Code
florentine_igraph_nodes$betweenness <- betweenness
Error in florentine_igraph_nodes$betweenness <- betweenness: object 'florentine_igraph_nodes' not found
Code
florentine_igraph_nodes$closeness <- closeness
Error in florentine_igraph_nodes$closeness <- closeness: object 'florentine_igraph_nodes' not found
Code
florentine_igraph_nodes
Error in eval(expr, envir, enclos): object 'florentine_igraph_nodes' not found

Here are some observations: - “Medici” stands out as the most central node in the network with the highest scores across multiple centrality measures: - Total degree: 6 - Indegree: 6 - Outdegree: 6 - Global transitivity: 0.1914894 - Average transitivity: 0.2181818 - Eigencentrality: 1.0000000 - Betweenness: 47.500000 - Closeness: 0.04000000

  • Nodes “Ginori,” “Lamberteschi,” “Acciaiuoli,” and “Pazzi” exhibit relatively lower centrality scores compared to others in the network:
    • Total degree: 1
    • Indegree: 1
    • Outdegree: 1
    • Global transitivity: 0.1914894
    • Average transitivity: 0.2181818
    • Eigencentrality: 0.1741141
    • Betweenness: 0.000000
    • Closeness: 0.02380952
  • Nodes “Guadagni,” “Strozzi,” “Ridolfi,” and “Albizzi” show higher centrality scores, indicating their significant roles within the network:
    • Total degree: 4
    • Indegree: 4
    • Outdegree: 4
    • Global transitivity: 0.1914894
    • Average transitivity: 0.2181818
    • Eigencentrality: 0.6718805 (Guadagni), 0.8272688 (Strozzi), 0.7937398 (Ridolfi), 0.5669336 (Albizzi)
    • Betweenness: 23.166667 (Guadagni), 9.333333 (Strozzi), 10.333333 (Ridolfi), 19.333333 (Albizzi)
    • Closeness: 0.03333333 (Guadagni), 0.03125000 (Strozzi), 0.03571429 (Ridolfi), 0.03448276 (Albizzi)