如何用iGraph挖掘R中的图案 [英] How to mine for motifs in R with iGraph
问题描述
我试图在R中使用包 igraph
来挖掘3节点图案。我想从graph.motifs()函数中获取图形中每个单独顶点的图案数目。
因此,对于示例图:
testGraph = barabasi.game(10,
m = 5,
power = 2,
out.pref = TRUE,
zero.appeal = 0.5,
directed = TRUE)
我可以使用 graph.motifs()
来计算整个图中每个3节点图案的总数:
graph.motifs(testGraph,
size = 3)
[1] 0 0 26 0 16 0 2 58 0 0 0 0 0 0 0 0
但我想知道单个顶点的参与。那么,顶点1参与了多少个主题(以及哪种类型)?有没有人知道一个简单的方法来做到这一点?
解决方案这是一个快速的操作方法。
它对顶点 A 的三元组感兴趣,然后首先创建包含 A 的诱导子图和它的直接邻居。您可以通过 neighborhood()
和 induced.subgraph()
或简单地使用图来实现。舒炎泰()
。
然后找到这个子图中的图形,但是不能用 graph.motifs()
,而是用 triad.census()
,因为这会计算所有可能的三元组,即使是非连接的元素也是如此。 然后从这个子图中删除 A ,再次调用 triad.census()
。两个计数向量的差别恰恰就是包含 的图案。
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?
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.
这篇关于如何用iGraph挖掘R中的图案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!