Visit Homepage
Skip to content

DataNinjas = read.csv(“software.csv”, head=T, sep=”;”, na.strings=na) (2)

[Recap: There’s tons of software out there to help you with your calculations, correlations, transformations, permutations, visualizations, … (here we go with the –ations again! Seriously! Maybe I should make a network out of them). There are all-rounders, like UCINET, some focus more on the numbers (such as R), others (Gephi for example) are geared toward those who like fancy spaghetti monsters (guess who?!). If you’re working with really large, or even HUGE data, Pajek’s your cup of tea, although it works just as well for small networks. There’s no such thing as “the best” program to work with, although everyone probably has a favorite. Gephi is our top choice, not just because of the fancy schmancy visuals, but also because it’s very user-friendly. When it comes to metrics, however, it’s pretty limited. For those, I turn to UCINET, while Silke gets her kicks in R (which is why she’s doing the R tutorial). Why? No idea. The fact that she took the introduction course to SNA & R and I the equivalent for UCINET at last year’s Sunbelt in Hamburg has nothing to do with this of course.

Anywho, over the next couple of posts we’ll let you know what we think of some of the major software programs, with tips ‘n tricks to help you out. If you have any questions, Google it, for cryin’ out loud, that brain of yours is there for a reason! Just kidding, we’re happy to help if we can. Not. No really, fire away… we dare you…]

As promised, this week is all about … *drumroll*… SNA and R!

Silke’s our in-house expert when it comes to R, though she’s leaving for King’s College in a couple of days. So I’ll be doing this over the next few weeks, presumably all at the same time:

R Tutorial network analysis tools temper-tantrum.gif

R Tutorial network analysis tools Lion-King.gif

R Tutorial network analysis tools Emma-Stone.gif

R Tutorial network analysis tools How-I-Met-Your-Mother1.gif
(So Mark, if I’ve gone missing, just check under my desk).

She’ll be working with some high-profile SNA’ists (who are also dealing with historical data!) at the Digital Humanities department, so when she gets back in a couple of months she’ll have climbed to the rank of SNA master and no network enigma will be too challenging for her! So this week, it’s her time to shiiiine! Hit it, babe!

R Tutorial

Besides being the glorious 18th letter of our alphabet – glorious because “rrrrrrrr” is the only letter to express the prelude of sexy-sexy times, and I’m fairly sure that’s why some movies are rated R – it is also the perfect letter to scare your co-workers in a ‘knights who say ni’-way to get them to leave your work station.

R Tutorial network analysis tools The-Knights-Who-Say-Ni.jpg

And yes, the DataNinjas have a work station, where all our hard work gets done and where, occasionally, we do some synchronised desk chair ballet. It’s like water ballet, but on a desk chair (the sort that has little wheels). You should try it, no really! Feel those upper leg muscles burn! (If at this point you’re facing a colleague, I’m so very sorry)

R tutorial network analysis tools 200.gifAnyway, let’s first get those brain muscles working as we’re about to get personal with our second software program: R! This versatile software can do ANYTHING when it comes to statistics (or at least anything a human brain with a relatively high IQ is capable of understanding. No doubt Sheldon has more tricks up his sleeves).

Several packages designed more or less specifically for SNA purposes can be downloaded and loaded into the program: sna, igraph, statnet, … . But before you can do that, let’s go surfing those waves and download the essential (open-source, hoorah!) software.
Then go and download this user-friendly interface.
Now that we’re all settled, time for some warnings!
R is pretty daunting, even for us first generation I-grew-up-with-a-computer-and-internet-what-do-you-mean-it-wasn’t-like-that-20-years-ago twats. In fact, that’s actually the problem. We’re so used to everything being streamlined into drop-down menu’s and functions that are just a click away, while in R you’re still required to actually type the “codes” of the calculations you want it to perform. Once you know what these codes are, it’s pretty simple (typo’s can get extremely annoying though, so watch your fingers!), resulting in a screen that makes you feel like Q decoding enemy Intel.

R tutorial network analysis tools wishaw_2378039b.jpg

Oh, is that Daniel Craig on the right?! Zoom in on him a bit!

R tutorial network analysis tools daniel+craig+speedo+4.jpg

Mmm, yummy…

Yanne, stop interfering with my post!

Sorry…

Anywho, the best way to get used to R, is to dive into it and into this R tutorial! We’ve provided a (very) short R Tutorial script for you to try out. This first chapter is on installing packages and importing data.

You can copy and paste the following instructions into the console of Rstudio and when you press enter – hey presto! – results will appear.

(lines preceded by # are just included for background info, the actual instructions (codes) that you enter in the R console aren’t preceded by anything, so for example just type in ‘library(sna)’ (without the quotation marks) and hit enter, and the package ‘sna’ wil be loaded.)

R Tutorial Chapter One: Installing packages and importing data:

# First time: installing packages
# e.g. package sna, statnet, igraph, network

install.packages( c(“sna”, “statnet”, “igraph”, “network”))

# can be done through Tools > Install Packages > fill in needed package(s): sna statnet igraph network
# Now these packages need to be loaded:

library(sna)
library(statnet)
library(igraph)
library(network)

# If you would like to import data from excel, make sure you know where you have saved it as you need to specify the location
# The simplest way is to set a working directory.

# Set working directory

setwd(“~/Documents/…”)

# Importing data from excel
# It is important to know in which format you have saved your data. Here we have used the .csv format, which we need to specify.

oef = read.csv(“name_of_your_file.csv”,
head=T,
sep=”;”,
na.strings=”na”)

# If at any point, you are unsure what to do or how to do it, you can ask R to help you by putting one or two question marks
# in front of the programming word you feel unsure about or in front of a general word, e.g. if you want more information on the read.csv function:

?read.csv

# or how to read a pajek project, but you do not know the function or programming word:

??pajek

# Back to our import!
# As you can see, head can be T or TRUE, also F or FALSE
# this is to specify whether you want to see the column names as they are in your csv.file or not
#
# head=T
# head=TRUE
# head=F
# head=FALSE
#
# A separator should be added when working with excel csv.files because excel uses ; instead of ,
#
# sep=”;”
#
# na.strings=”na” fills in the empty spaces with the symbol “na” for not available.
#
# Now we should check whether our data have been correctly imported.

head(oef)
tail(oef)

# End of first chapter R Tutorial

Now, if you would like to learn more about R, you could try this online tutorial or ask a question to one of the R-bloggers.

As always, your devoted servants,
Yanne and Silke

R tutorial network analysis tools 1002_daniel-craig-21_ob.jpg

(Can’t help it, I’ll be browsing Google images for the rest of the afternoon…)

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *