This function takes an nCol file and returns L.C. Freeman’s Group Degree Centrality:

Degree centrality (C_{D}) can be calculated as follows:

For the following graph

we can count the number of connections (edges) each node has (its degree),

n1 3
n2 1
n3 1
n4 2
n5 1

The maximum degree is 3 for *n1*. Therefore we subtract the other node degrees from this

n1 3 (3-3) 0
n2 1 (3-1) 2
n3 1 (3-1) 2
n4 2 (3-2) 1
n5 1 (3-1) 2

Then we add all values from the difference to get our enumerator,

0+2+2+1+2 = 7

We then have to calculate the denominator, where `n`

is the total number of nodes, in this case 5.

(n-1)(n-2)
(5-1)(5-2)=12

Finally, we divide both numbers to get the group’s C_{D}

7/12 = 0.58

This is the R bit.

Format of the input file is:

user1 user2 2010-01-01
user3 user4 2001-04-03

The file is loaded to R as a data frame, with `stringsAsFactors=FALSE`

df<-data.frame(read.csv('location/of/ncol.txt',dep=" ",stringsAsFactors=FASLE,header=FALSE))
# Run the function
ncol.CDi(df)

This is the function

ncol.CDi<-function(df){
# Remove the date column
df[3]<-NULL
# Remove self Loops
dx<-df[!df[1]==df[2], ]
# removes duplicates
dx1<-unique(dx)
dx2<-data.frame(unique(t(apply(dx1, 1, sort))))
# Move all into one Column
colnames(dx2)<-c('x','x')
dx3<-rbind(dx2[1],dx2[2])
# gets frequency
df1<-data.frame(table(dx3))
# order according to frequency
df2<-df1[with(df1,order(-Freq)),]
rownames(df2) <- 1:nrow(df2)
# calculate biggest value
bv<-df2[1,2]
# Create new column with difference
# between biggest value and node value
df2$diff<-bv-df2[2]
# Add all differences
cSum<-sum(df2$diff)
# dive them by total possible
# and return 0-1 index
nN<-length(df2[,1])
tpn<-(nN-1)*(nN-2)
cSum/tpn
}

### Like this:

Like Loading...

*Related*