【问题标题】:how to plot degree distribution in R如何在R中绘制度数分布
【发布时间】:2013-01-06 17:43:00
【问题描述】:

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

所以脚本是(我所有顶点度数的向量都存储在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

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 中的图吗?

【问题讨论】:

    标签: r plot distribution power-law


    【解决方案1】:

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

    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,而您正在进行简单的线性回归(不推荐)。


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

    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)
    

    【讨论】:

    • mle 是如何产生这些差异的?有简单的解释吗?
    • 对不起,你能解释一下吗..所以观察到的模式是正确的?
    猜你喜欢
    • 1970-01-01
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 2020-10-16
    • 2015-05-04
    • 1970-01-01
    • 2013-08-01
    相关资源
    最近更新 更多