3

我想知道绘制度数分布的脚本输出是否正确。

所以脚本是(其中具有我所有顶点度数的向量存储在x中):

x 是

x
 [1] 7 9 8 5 6 2 8 9 7 5 2 4 6 9 2 6 10 8 

x 是某个网络顶点的度数 - 就像顶点 1 的度数为 7,顶点 2 的度数为 9,依此类推 x <- v2 summary(x)

library(igraph)
split.screen(c(1,2))
screen(1)
plot (tabulate(x), log = "xy", ylab = "Frequency (log scale)", xlab = "Degree (log scale)", main = "Log-log plot of degree distribution")
screen(2)
y <- (length(x) - rank(x, ties.method = "first"))/length(x)
plot(x, y, log = "xy", ylab = "Fraction with min. degree k (log scale)", xlab = "Degree (k) (log scale)", main = "Cumulative log-log plot of degree distribution")
close.screen(all = TRUE)
power.law.fit(x, xmin = 50)

我的问题是对数图似乎不正确 - 例如,我的度数为 8 次,所以对数图上的这一点不应该变成 0.845 (log 7)/0.903 (log( 8) 如 (x/y)?

此外,有人能告诉我如何将线(对数刻度上的幂律)拟合到屏幕 2 中的图吗?

4

1 回答 1

6

我不熟悉这个igraph包,所以你不能帮助那个特定的包。但是,这里有一些用于在对数图上绘制分布的代码。首先是一些数据:

set.seed(1)
x = ceiling(rlnorm(1000, 4))

然后我们需要重新排列得到逆CDF:

occur = as.vector(table(x))
occur = occur/sum(occur)
p = occur/sum(occur)
y = rev(cumsum(rev(p)))
x = as.numeric(names(table(x)))
plot(x, y, log="xy", type="l")

在此处输入图像描述

关于您的拟合问题,我认为出现差异是因为igraph使用 MLE 而您正在进行简单的线性回归(不推荐)。


作为一个小插曲,我已经开始研究一个用于拟合和绘制幂律的包。所以,使用这个包你得到:

library(poweRlaw)

##Create a displ object
m = displ$new(x)
##Estimate the cut-off
estimate_xmin(m)
m$setXmin(105); m$setPars(2.644)

##Plot the data and the PL line
plot(m)
lines(m, col=2)

在此处输入图像描述

于 2013-01-23T10:50:23.003 回答