1. Degree Centrality Measures
setwd("D:/R_Labs")
data<- "sample_adjmatrix.csv"
el<-read.table(data, header=T, row.names=1, sep=",")
m=as.matrix(el)
gplot(m, displaylabels=TRUE)
sna::degree(m)
## [1] 6 8 2 8 4 10 2
sna::degree(m, cmode = "indegree")
## [1] 3 4 1 4 2 5 1
sna::degree(m,cmode="outdegree")
## [1] 3 4 1 4 2 5 1
# Calculate the degree of m using gapply
gapply(m,1,rep(1,7),sum)
## 23732 23778 23824 23871 58009 58098 58256
## 3 4 1 4 2 5 1
2. Basic Centrality Measures
Degree, Clonseness, Betweenness
Comparisons between Degree and Betweenness
dg<- sna::degree(m)
bt<- sna::betweenness(m)
plot(bt,dg, xlab="Betweenness Centrality", ylab="Degree Centrality", main = "Degree vs. Betweenness", col="red", pch=5)
gplot(m, vertex.cex=sqrt(dg) , displaylabels=TRUE)
gplot(m, vertex.cex=sqrt(bt)+1 , displaylabels=TRUE)
3. Create geodesic path count and geodesic distance matrix
geodist(m)
## $counts
## [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 1 1 1 1 2 1 1
## [2,] 1 1 1 1 2 1 1
## [3,] 1 1 1 1 2 1 1
## [4,] 1 1 1 1 1 1 1
## [5,] 2 2 2 1 1 1 1
## [6,] 1 1 1 1 1 1 1
## [7,] 1 1 1 1 1 1 1
##
## $gdist
## [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 0 1 2 1 2 1 2
## [2,] 1 0 1 1 2 1 2
## [3,] 2 1 0 2 3 2 3
## [4,] 1 1 2 0 1 1 2
## [5,] 2 2 3 1 0 1 2
## [6,] 1 1 2 1 1 0 1
## [7,] 2 2 3 2 2 1 0
$counts: a matrix containing the number of geodesics between each pair of vertices
$gdist: a matrix containing the geodesic distances between each pair of vertices