ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Centralities for undirected networks

juliouibpeApuntes19 de Noviembre de 2022

6.785 Palabras (28 Páginas)74 Visitas

Página 1 de 28

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 Guadagni Strozzi Ridolfi Albizzi

## 1.006 1.004 1.004 1.003 1.003

## Tornabuoni Bischeri Castellani Peruzzi Barbadori

## 1.003 1.003 1.003 1.003 1.002

## Salviati Acciaiuoli Lamberteschi Ginori Pazzi

## 1.002 1.001 1.001 1.001 1.001

round(sort(decay(FLOp, decay=0.25),decreasing=TRUE),4)

## Medici Guadagni Strozzi Ridolfi Albizzi

## 2.8594 2.3789 2.3203 2.2969 2.2500

## Tornabuoni Bischeri Castellani Peruzzi Barbadori

## 2.2500 2.1182 2.0273 2.0127 2.0039

## Salviati Acciaiuoli Lamberteschi Ginori Pazzi

## 1.8867 1.6523 1.5322 1.5000 1.4092

round(sort(decay(FLOp, decay=0.75),decreasing=TRUE),4)

## Medici Ridolfi Albizzi Tornabuoni Guadagni

## 9.5781 9.0156 8.8750 8.8750 8.8164

## Strozzi Barbadori Bischeri Castellani Salviati

## 8.5703 8.4414 8.1982 7.9961 7.9492

## Peruzzi Acciaiuoli Ginori Lamberteschi Pazzi

## 7.8115 7.6211 7.0938 7.0498 6.3994

The centroid centrality is computed with centiserve’s centroid function:

sort(centroid(FLOp),decreasing=TRUE)

## Medici Guadagni Ridolfi Albizzi Strozzi

## 0 -3 -3 -4 -4

## Tornabuoni Bischeri Peruzzi Barbadori Castellani

## -4 -5 -6 -7 -7

## Salviati Acciaiuoli Ginori Lamberteschi Pazzi

## -11 -13 -13 -13 -13

Now, the centers of the network are

which(eccentricity(FLOp)==min(eccentricity(FLOp)))

## Albizzi Medici Ridolfi Tornabuoni

## 2 9 12 15

Its medians are

which(igraph::closeness(FLOp,normalized=TRUE)==max(igraph::closeness(FLOp,normalized=TRUE)))

## Medici

## 9

And its centroids are

which(centroid(FLOp)==max(centroid(FLOp)))

## Medici

## 9

Betweenness centralities

The betweenness centrality of a node is computed with the function betweenness in igraph or in sna (different usage).

round(igraph::betweenness(FLOp,v="Medici"),4)

## Medici

## 47.5

round(igraph::betweenness(FLOp),4)

## Acciaiuoli Albizzi

...

Descargar como (para miembros actualizados) txt (29 Kb) pdf (70 Kb) docx (567 Kb)
Leer 27 páginas más »
Disponible sólo en Clubensayos.com