I would like to know whether the output of a script to plot a degree distribution can be correct.
我想知道一个脚本的输出是否可以画出一个度分布是正确的。
So the script is ( where the vector with the degrees of all my vertices is stored in x):
所以这个脚本是(在这里,所有顶点的度数都存储在x中):
x is
x是
x
[1] 7 9 8 5 6 2 8 9 7 5 2 4 6 9 2 6 10 8
x is the degree of a certain network vertice - like vertice 1 has degree 7, vertice 2 has degree 9 and so on x <- v2 summary(x)
x是某个网络顶点的度数,比如vertice 1有7度,顶点2有9度,所以在x <- v2摘要(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)
My problem is that the log-log plot seems to be incorrect - for instance, I have the degree '7' 8 times overall so shouldn't this point on a log-log plot become 0.845 (log 7)/ 0.903 (log(8) as in (x/y)?
我的问题是,log-log的情节似乎是不正确的——例如,我的总体积是“7”的8倍,因此,在日志-日志的情节中,这一点不应该变成0.845 (log 7)/ 0.903 (log(8)) (x/y)吗?
Moreover, can somebody tell me how to fit the line ( the power-law on the log-log scale) to the plot in the screen 2 ?
另外,谁能告诉我如何将这条线(对数对数尺度上的幂律)与屏幕2中的情节相匹配?
1 个解决方案
#1
4
I'm not familar with the igraph
package, so can't you help with that specific package. However, here is some code for plotting distributions on the log-log plot. First some data:
我不熟悉igraph软件包,所以你不能帮我处理那个特定的软件包。但是,这里有一些用于在日志-日志图上绘制分布的代码。首先一些数据:
set.seed(1)
x = ceiling(rlnorm(1000, 4))
Then we need to rearrange the to get the inverse CDF:
然后我们需要重新排列得到逆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")
Gives
给了
Regarding your fitting question, I think the discrepancy arises because igraph
uses the MLE whereas you are doing simple linear regression (which is not recommended).
关于你的拟合问题,我认为存在差异是因为igraph使用MLE而你做的是简单的线性回归(这是不推荐的)。
As a bit of a plug, I've started work on a package for fitting and plotting powerlaws. So, using this package you get:
作为一个插件,我已经开始为拟合和绘制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)
#1
4
I'm not familar with the igraph
package, so can't you help with that specific package. However, here is some code for plotting distributions on the log-log plot. First some data:
我不熟悉igraph软件包,所以你不能帮我处理那个特定的软件包。但是,这里有一些用于在日志-日志图上绘制分布的代码。首先一些数据:
set.seed(1)
x = ceiling(rlnorm(1000, 4))
Then we need to rearrange the to get the inverse CDF:
然后我们需要重新排列得到逆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")
Gives
给了
Regarding your fitting question, I think the discrepancy arises because igraph
uses the MLE whereas you are doing simple linear regression (which is not recommended).
关于你的拟合问题,我认为存在差异是因为igraph使用MLE而你做的是简单的线性回归(这是不推荐的)。
As a bit of a plug, I've started work on a package for fitting and plotting powerlaws. So, using this package you get:
作为一个插件,我已经开始为拟合和绘制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)