10

考虑一个数据框df,其中前两列是节点对,连续列V1, V2, ...Vn表示节点之间的流(可能为 0,表示该列的网络没有边)。我想使用流作为权重对程度、社区检测和其他网络度量进行分析。

V1然后根据我的权重分析图表:

# 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 的输出与第一个没有什么不同。我究竟做错了什么?

更新:

graph.strength正在寻找的也是如此,但graph.strength(g)在我的情况下,给出标准学位输出,然后是:

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

4

2 回答 2

7

graph.strength可以给函数一个带有weights参数的权重向量。我认为您的代码中出现的问题是您不应该调用 weightsE(g)$weight属性E(g)$weights

于 2011-12-01T17:20:40.990 回答
4

通过获取代码并进行更改degree.distribution,我为自己的代码创建了加权图的等效函数:degree.distribution

graph.strength.distribution <- function (graph, cumulative = FALSE, ...)
{
  if (!is.igraph(graph)) {
    stop("Not a graph object")
  }
  # graph.strength() instead of degree()
  cs <- graph.strength(graph, ...)
  hi <- hist(cs, -1:max(cs), plot = FALSE)$density
  if (!cumulative) {
    res <- hi
  }
  else {
    res <- rev(cumsum(rev(hi)))
  }
  res
}
于 2011-12-02T02:01:41.577 回答