Centralities for undirected networks
Enviado por juliouibpe • 19 de Noviembre de 2022 • Apuntes • 6.785 Palabras (28 Páginas) • 45 Visitas
Centralities for undirected networks
We shall compute several centrality indices on the Florentine families wedding network. For obvious reasons, we shall only consider the giant component.
library(network)
library(igraph)
library(centiserve)
library(sna)
library(printr)
We define the corresponding network FLOp and we extract some information about it:
data(flo)
FLO=graph_from_adjacency_matrix(flo,mode="undirected")
FLOp=delete_vertices(FLO,"Pucci")
VF=as_ids(V(FLOp)) #Vector of nodes
EF=as_ids(E(FLOp)) #Vector of edges
n=gorder(FLOp) #Order
m=ecount(FLOp) #Size
M=as.matrix(as_adjacency_matrix(FLOp)) # The adjacency matrix
plot(FLOp)
Names=attr(V(FLOp), "names")
Edges=attr(E(FLOp), "vnames")
Degree centralities
The (normalized) degree centrality of a node is simply (a normalized version of) its degree, as computed with degree in igraph :
round(igraph::degree(FLOp,normalized=TRUE),4)
## Acciaiuoli Albizzi Barbadori Bischeri Castellani
## 0.0714 0.2143 0.1429 0.2143 0.2143
## Ginori Guadagni Lamberteschi Medici Pazzi
## 0.0714 0.2857 0.0714 0.4286 0.0714
## Peruzzi Ridolfi Salviati Strozzi Tornabuoni
## 0.2143 0.2143 0.1429 0.2857 0.2143
Do not confuse it with degree in sna
sna::degree(M,gmode="graph") #sna works with adjacency matrices
## [1] 1 3 2 3 3 1 4 1 6 1 3 3 2 4 3
sna::degree(M,gmode="graph",rescale=TRUE)
## [1] 0.025 0.075 0.050 0.075 0.075 0.025 0.100 0.025 0.150 0.025 0.075
## [12] 0.075 0.050 0.100 0.075
round(sna::degree(M,gmode="graph")/(n-1),4)
## [1] 0.0714 0.2143 0.1429 0.2143 0.2143 0.0714 0.2857 0.0714 0.4286 0.0714
## [11] 0.2143 0.2143 0.1429 0.2857 0.2143
The lobby centrality (actually, a modification of it, because it includes the node itself in its neighborhood) can be computed with the function lobby in the centiserve package:
lobby(FLOp,v="Medici") #One node
## Medici
## 3
lobby(FLOp)
## Acciaiuoli Albizzi Barbadori Bischeri Castellani
## 1 3 2 3 3
## Ginori Guadagni Lamberteschi Medici Pazzi
## 1 3 1 3 1
## Peruzzi Ridolfi Salviati Strozzi Tornabuoni
## 3 3 2 3 3
The lobby centrality as defined in the lectures can be computed with the following function TLC:
TLC=function(G,v=as_ids(V(G))){
HH=function(x){
require(igraph)
D=as.numeric(igraph::degree(G, v=neighbors(G,v=x)))
z=sort(D,decreasing=TRUE)-(1:length(D))
max(which(z>=0))
}
unlist(sapply(v,FUN=HH))
}
TLC(FLOp,c("Medici","Albizzi"))
## Medici Albizzi
## 3 2
TLC(FLOp)
## Acciaiuoli Albizzi Barbadori Bischeri Castellani
## 1 2 2 3 2
## Ginori Guadagni Lamberteschi Medici Pazzi
## 1 3 1 3 1
## Peruzzi Ridolfi Salviati Strozzi Tornabuoni
## 3 3 1 3 3
Closeness centralities
The usual mean closeness centrality is closeness in igraph or in sna (with different syntax):
round(igraph::closeness(FLOp,normalized=TRUE,v="Medici"),4) #one node
## Medici
## 0.56
round(igraph::closeness(FLOp,normalized=TRUE),4)
## Acciaiuoli Albizzi Barbadori Bischeri Castellani
## 0.3684 0.4828 0.4375 0.4000 0.3889
## Ginori Guadagni Lamberteschi Medici Pazzi
## 0.3333 0.4667 0.3256 0.5600 0.2857
## Peruzzi Ridolfi Salviati Strozzi Tornabuoni
## 0.3684 0.5000 0.3889 0.4375 0.4828
round(sort(igraph::closeness(FLOp,normalized=TRUE),decreasing =TRUE),4)
## Medici Ridolfi Albizzi Tornabuoni Guadagni
## 0.5600 0.5000 0.4828 0.4828 0.4667
## Barbadori Strozzi Bischeri Castellani Salviati
## 0.4375 0.4375 0.4000 0.3889 0.3889
## Acciaiuoli Peruzzi Ginori Lamberteschi Pazzi
## 0.3684 0.3684 0.3333 0.3256 0.2857
round(sna::closeness(M,gmode="graph"),4)
## [1] 0.3684 0.4828 0.4375 0.4000 0.3889 0.3333 0.4667 0.3256 0.5600 0.2857
## [11] 0.3684 0.5000 0.3889 0.4375 0.4828
The other closeness centrality indices can be computed in an ad hoc way: the maximum closeness centrality:
round(sort(1/eccentricity(FLOp),decreasing =TRUE),4)
## Albizzi Medici Ridolfi Tornabuoni Acciaiuoli
## 0.3333 0.3333 0.3333 0.3333 0.2500
## Barbadori Castellani Ginori Guadagni Salviati
## 0.2500 0.2500 0.2500 0.2500 0.2500
## Strozzi Bischeri Lamberteschi Pazzi Peruzzi
## 0.2500 0.2000 0.2000 0.2000 0.2000
The other mean closeness centrality:
round(sort(diameter(FLOp)+1-1/igraph::closeness(FLOp,normalized=TRUE),decreasing =TRUE),4)
## Medici Ridolfi Albizzi Tornabuoni Guadagni
## 4.2143 4.0000 3.9286 3.9286 3.8571
## Barbadori Strozzi Bischeri Castellani Salviati
## 3.7143 3.7143 3.5000 3.4286 3.4286
## Acciaiuoli Peruzzi Ginori Lamberteschi Pazzi
## 3.2857 3.2857 3.0000 2.9286 2.5000
The decay centrality is implemented in centiserve’s decay function:
round(sort(decay(FLOp, decay=0.001),decreasing=TRUE),4)
## Medici
...