簡體   English   中英

如何在R中繪制度分布

[英]how to plot degree distribution in R

我想知道繪制度分布的腳本輸出是否正確。

因此,腳本是(將所有頂點的度數的矢量存儲在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)

我的問題是對數-對數圖似乎不正確-例如,我的整體分數為'7'8倍,因此對數-對數圖上的這一點不應變成0.845(log 7)/ 0.903(log( 8)如(x / y)?

此外,有人可以告訴我如何將線(對數對數刻度上的冪律)擬合到屏幕2中的圖嗎?

我對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)

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM