如何在R中绘制度分布图

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)

x是一个变量,被赋值为v2的值。summary(x)会显示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)

我的问题是,似乎Log-Log图不正确——例如,我总共有8个“7”度数,那么在Log-Log图上,这个点不应该成为0.845(log 7) / 0.903 (log(8)如(x/y)所示吗?
此外,有人可以告诉我如何将线(对数-对数比例上的幂律)拟合到屏幕2中的图形上吗?
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")

给出

enter image description here

关于您的拟合问题,我认为差异是由于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)

enter image description here


MLE如何产生这些差异?有简单的解释吗? - Tim Heinert
抱歉,您能解释一下吗?这样观察到的模式是正确的吗? - Tim Heinert

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接