[英]Creating new measures in igraph
I want to create a function for Burt's effective size. 我想为Burt的有效尺寸创建一个函数。 The formula boils down to: 该公式归结为:
Effective size = n - 2t/n 有效尺寸= n - 2t / n
I'm not really sure where to start with writing functions within/for igraph. 我不确定从哪里开始编写/ for igraph中的函数。
Let me know if more detail would be helpful... 如果有更多细节会有帮助,请告诉我......
Thanks. 谢谢。
First simulate a basic graph: 首先模拟一个基本图表:
require(igraph)
alters = 50
ties = 10
set.seed(12345)
edgelist = rbind(0, 1:alters)
edgelist = cbind(edgelist, replicate(ties, sample(alters, 2)))
g = graph(edgelist, directed=F)
dev.new(width=5, height=5)
plot(g, layout=layout.kamada.kawai)
Then write a simple function to calculate the effective size. 然后编写一个简单的函数来计算有效大小。 (The functions in here that operate on g
are all nicely documented in the igraph
manual and in various examples around the net.) (这里对g
进行操作的函数都很好地记录在igraph
手册和网络的各种例子中。)
EffectiveSize <- function(g, ego=0) {
n = neighbors(g, ego)
t = length(E(g)[to(n) & !to(ego)])
n = length(n)
n - 2 * t / n
}
> EffectiveSize(g)
[1] 49.6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.