Tim*_*ert 2 plot r distribution power-law
我想知道绘制度分布的脚本输出是否正确.
所以脚本是(其中我的所有顶点的度数的向量都存储在x中):
x是
x
[1] 7 9 8 5 6 2 8 9 7 5 2 4 6 9 2 6 10 8
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
我的问题是log-log图似乎是不正确的 - 例如,我的整体度为'7'8倍,所以不应该在log-log图上的这一点变为0.845(log 7)/ 0.903(log( 8)如(x/y)?
此外,有人可以告诉我如何将线(对数对数刻度上的幂律)拟合到屏幕2中的图中吗?
我不熟悉这个igraph包,所以你不能帮忙解决这个问题.但是,这里有一些用于在log-log图上绘制分布的代码.首先是一些数据:
set.seed(1)
x = ceiling(rlnorm(1000, 4))
Run Code Online (Sandbox Code Playgroud)
然后我们需要重新排列以获得逆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")
Run Code Online (Sandbox Code Playgroud)
给

关于你的拟合问题,我认为出现差异是因为igraph使用MLE而你正在进行简单的线性回归(不推荐).
作为一个插件,我已经开始研究用于拟合和绘制powerlaws 的包.所以,使用这个包你会得到:
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)
Run Code Online (Sandbox Code Playgroud)
