Difference between revisions of "Social Network Analysis With Igraph Package Using R"

From AIRWiki
Jump to: navigation, search
(Macroscopic Analysis)
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Install the package under R environmemnt ==
 
== Install the package under R environmemnt ==
  
type the command:
+
under Ubuntu install the R package:
  <code>install.packages("igraph")</code>
+
  <code>sudo apt-get install r-base-core</code>
  
 +
type R to start the program:
 +
<code>R</code>
 +
 +
type the command to download and install igraph as R library:
 +
<code>install.packages("igraph")</code>
  
 
== Starting with the package ==
 
== Starting with the package ==
Line 9: Line 14:
 
  <code>library('igraph')</code>
 
  <code>library('igraph')</code>
 
parse a network file in Pajek format and access to its memory representation through the variable 'g':
 
parse a network file in Pajek format and access to its memory representation through the variable 'g':
  <code>g <- read.graph(file='/your/path/.../file.net', format='pajek')</code>
+
  <code>g <- read.graph(file='/your/path/.../file.net', [[pajek graph data format|format='pajek']])</code>
 
list vertex and their attributes of graph g:
 
list vertex and their attributes of graph g:
 
  <code>
 
  <code>
Line 27: Line 32:
 
<code>
 
<code>
 
  plot(g)
 
  plot(g)
 +
tkplot(g)
 
</code>
 
</code>
  
 
== Macroscopic Analysis ==
 
== Macroscopic Analysis ==
graph size (number of nodes):
+
'''graph size''' (number of nodes): length(V(g))
  
number of edges:
+
'''number of edges''': length(E(g))
  
mean degree:
+
'''diameter''': diameter(g)
  
density:
+
'''mean degree''':
  
giant component size (the largest connected component size):
+
'''density''':
  
== Node Centrality Analysis ==
+
'''giant component size''' (the largest connected component size):
  
degree:
+
assortativity:
  
closeness:
+
== Node Centrality Analysis ==
  
betweenness:
+
'''degree''': degree(g)
  
eigenvector/pagerank:
+
'''closeness''': closeness(g)
  
assortativity:
+
'''betweenness''': betweenness(g)
 +
 
 +
'''eigenvector'''/'''pagerank''': evcent(g)
  
 
== Clustering Techniques ==
 
== Clustering Techniques ==
  
connected components:
+
'''connected components''': clusters(g)
  
edge betweenness:
+
'''edge betweenness''':
  
walktrap:
+
'''walktrap''':
  
spinglass:
+
'''spinglass''':
  
 
== References and further informations ==
 
== References and further informations ==

Latest revision as of 12:43, 16 March 2011

Install the package under R environmemnt

under Ubuntu install the R package:

sudo apt-get install r-base-core

type R to start the program:

R

type the command to download and install igraph as R library:

install.packages("igraph")

Starting with the package

don't forget to load the library:

library('igraph')

parse a network file in Pajek format and access to its memory representation through the variable 'g':

g <- read.graph(file='/your/path/.../file.net', format='pajek')

list vertex and their attributes of graph g:


V(g)                      # the list of all nodes
V(g)[0]                   # access the first node
list.vertex.attributes(g) # the list of all vertex attributes names
V(g)[0]$id                # access the attribute 'id' for the first node

list edges/arcs and their attributes of graph g:

E(g)                      # the list of all edges/arcs
E(g)[0]                   # access the first edge/arc
list.edge.attributes(g)   # the list of all edges/arcs attributes names
E(g)[0]$weight            # access the attribute 'weight' for the first node

draw the graph:

plot(g)
tkplot(g)

Macroscopic Analysis

graph size (number of nodes): length(V(g))

number of edges: length(E(g))

diameter: diameter(g)

mean degree:

density:

giant component size (the largest connected component size):

assortativity:

Node Centrality Analysis

degree: degree(g)

closeness: closeness(g)

betweenness: betweenness(g)

eigenvector/pagerank: evcent(g)

Clustering Techniques

connected components: clusters(g)

edge betweenness:

walktrap:

spinglass:

References and further informations

Igraph/R documentation: http://igraph.sourceforge.net/doc/R/00Index.html