Categories
Uncategorized

Calculating Degree Centrality – R

Degree Centrality measures how connected an actor is within a social group. A very simple way of calculating this is by simply counting the number of connection, where you end up with an integer like 4 or 12.

Integers, however, don’t really work when you’re trying to compare Degree Centrality between actors in two social groups. For example, if an actor in a small social group of 5 has 4 connections, you could say he’s pretty connected. Whereas an actor with 12 connections in a social group of 25 is not. This is why integers like 4 and 12 are pretty useless.

This is where the Degree Centrality Index comes into play, since it calculates the connections an actor has with direct relation to the highest possible number in their social group.

In other words, if they’re in a group of five, each actor has a maximum of four possible connections (since they can’t really connect to themselves). So if they have four connections, then they have maximum degree centrality index. Four connections divided by four possible connections = 1 (4/4=1).

At the same time, if an actor has 12 connections in a group of 25, then their degree centrality index is 0.5, since 12/24=0.5 (where 24 is the maximum number of connections they can have).

Sounds pretty simple, and it is.

Here’s the actual equation, courtesy of L. C. Freeman, who came up with it a few decades ago.

So, lets calculate this using R.

Starting with the following ncol file.


dave sam
sam nick
nick dave
lisa joe
joe nick
katy beth

Same thing in graph form,

…then we do this to it.

# We load the file on to R as a Data Frame
dfNC <- data.frame(read.table("/location/of/ncolList.txt"))

# Rename columns the same thing so that we can...
colnames(dfNC)<-c("N","N")

# ...append column 2 under column 1.
dfNL <- rbind(dfNC[1],dfNC[2])

# we now get the frequency column
dfNL <- data.frame(table(dfNL))

# change names again and order rows according to frequency (although not really needed).
colnames(dfNL)<-c("N","Freq")
dfNL <- dfNL[with(dfNL,order(-Freq)),]
rownames(dfNL) <- 1:nrow(dfNL)

# This is the bit that calculates Degree Centrality...
dfNL$Cd<-dfNL[2]/(nrow(dfNL)-1)

This is my output

     N   Freq    Cd
1 nick    3     0.50
2 dave    2     0.33
3  joe    2     0.33
4  sam    2     0.33
5 katy    1     0.16
6 lisa    1     0.16
7 beth    1     0.16

Lazy Man’s Copy+Paste

dfNC <- data.frame(read.table("/location/of/ncolList.txt"))
colnames(dfNC)<-c("N","N")
dfNL <- rbind(dfNC[1],dfNC[2])
dfNL <- data.frame(table(dfNL))
colnames(dfNL)<-c("N","Freq")
dfNL <- dfNL[with(dfNL,order(-Freq)),]
rownames(dfNL) <- 1:nrow(dfNL)
dfNL$Cd<-dfNL[2]/(nrow(dfNL)-1)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s