如何在R中使用igraph计算加权度分布? [英] How do I calculate weighted degree distributions with igraph in R?
问题描述
考虑一个数据帧df
,其中前两列是节点对,连续列V1
,V2
,...,Vn
表示节点之间的流(可能为0,这意味着该列的边缘没有边缘网络).我想使用流作为权重对学位,社区发现和其他网络度量进行分析.
Consider a dataframe df
where the first two columns are node pairs and successive columns V1
, V2
, ..., Vn
represent flows between the nodes (potentially 0, implying no edge for that column's network). I would like to conduct analysis on degree, community detection, and other network measures using the flows as weights.
然后根据我在V1
中的权重来分析图形:
Then to analyze the graph with respect to the weights in V1
I do:
# create graph and explore unweighted degrees with respect to V1
g <- graph.data.frame( df[df$V1!=0,] )
qplot(degree(g))
x <- 0:max(degree(g))
qplot(x,degree.distribution(g))
# set weights and explore weighted degrees using V1
E(g)$weights <- E(g)$V1
qplot(degree(g))
第三个qplot的输出与第一个qplot的输出相同.我在做什么错了?
The output from the third qplot is no different than the first. What am I doing wrong?
更新:
所以 graph.strength
是我想要的,但是在我的情况下,graph.strength(g)
提供标准学位输出,其后是:
So graph.strength
is what I am looking for, but graph.strength(g)
in my case gives standard degree output followed by:
Warning message:
In graph.strength(g) :
At structural_properties.c:4928 :No edge weights for strength calculation,
normal degree
我必须设置错误的权重,这样做E(g)$weights <- E(g)$V1
是否还不够?为什么g$weights
与E(g)$weights
有区别?
I must be setting the weights incorrectly, is it not sufficient to do E(g)$weights <- E(g)$V1
and why can g$weights
differ from E(g)$weights
?
推荐答案
可以使用weights
参数为函数graph.strength
提供权重向量.我认为您的代码出了什么问题,您应该调用weights属性E(g)$weight
而不是E(g)$weights
.
The function graph.strength
can be given a weights vector with the weights
argument. I think what is going wrong in your code is that you should call the weights attribute E(g)$weight
not E(g)$weights
.
这篇关于如何在R中使用igraph计算加权度分布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!