Categories
data science

Calculating network structure using Bradford’s Law – R

The method, based on Kevin Crowston et al’s “Core and Periphery” paper, is explained in greater detail here.

This is the same as the other post, but it is now in a more convenient function form.

The R Function

bradford.structure <- function(df){
	df <- df[rev(order(df[2])),]
	df$pcp <- df[2]/sum(df[2])
	df$cs <- cumsum(df$pcp)
	df$layers[(df$cs)<=0.333]<-1
	df$layers[(df$cs)>0.333]<-2
	df$layers[(df$cs)>0.666]<-3
	return(df)
}

To run the function you need to first load a file with all the user names and number of posts

# user_file.txt
user        posts
jose        54
Latifah     34
Levondia    31
Laquisha    12

We load it as a normal data frame

df <- read.csv('path/to_my/user_file.txt',sep='\t')

Once it’s loaded, we use the above function ….

df_layers <- bradford.structure(df)

…and that’s it.

DONE!

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