How to mine for motifs in R with iGraph

我们两清 提交于 2019-12-03 03:20:51

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.

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)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!