Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mine for motifs in R with iGraph

Tags:

graph

r

igraph

I'm trying to mine for 3-node motifs in R using the package igraph. I would like to retrieve the number of motifs for each individual vertex in the graph, which does not appear possible from the graph.motifs() function.

So, for the example graph:

testGraph = barabasi.game(10, 
m = 5,
power = 2, 
out.pref = TRUE,
zero.appeal = 0.5,
directed = TRUE)

I can use graph.motifs() to count the total number of each 3-node motif in the entire graph:

graph.motifs(testGraph, 
size = 3)

[1] 0 0 26 0 16 0 2 58 0 0 0 0 0 0 0 0

But I would like to know the individual vertex participation. So, how many motifs (and what type) does vertex 1 participate in? Does anybody know a simple way to do that?

like image 514
Erin Shellman Avatar asked Sep 11 '12 17:09

Erin Shellman


Video Answer


2 Answers

Here is a quick how-to.

It you are interested in the triads of vertex A, then first create the induced subgraph that contains A and its immediate neighbors. You can do this via neighborhood() and induced.subgraph() or simply with graph.neighborhood().

Then find the motifs in this subgraph, but not with graph.motifs(), but rather with triad.census(), because that counts all possible triples, even a non-connected ones.

Then remove A from this subgraph, and call triad.census() again. The difference of the two count vector will be exactly the motifs that include A.

like image 117
Gabor Csardi Avatar answered Sep 21 '22 17:09

Gabor Csardi


Here's a self-contained example of Gabor's solution:

testGraph = barabasi.game(10, 
    m = 5,
    power = 0.6, 
    out.pref = TRUE,
    zero.appeal = 0.5,
    directed = TRUE)

# Label nodes to more easily keep track during subsets/deletions
V(testGraph)$name = c('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten')

subGraph = graph.neighborhood(testGraph, order = 1, V(testGraph)[1], mode = 'all')[[1]]
allMotifs = triad.census(subGraph)
removeNode = delete.vertices(subGraph, 'one')
node1Motifs = allMotifs - triad.census(removeNode)
like image 25
Erin Shellman Avatar answered Sep 25 '22 17:09

Erin Shellman