2013-01-23 84 views
2

我想知道腳本的輸出結果是否正確。如何在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 摘要(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)as在(x/y)?

此外,有人可以告訴我如何在屏幕2中繪製圖線(對數 - 對數刻度上的冪律)?

回答

4

我不熟悉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,而您正在進行簡單線性迴歸(不推薦)。


由於有點塞,我已經在package開始工作裝配和繪圖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) 

enter image description here

+0

如何MLE產生這些差異?有一個簡單的解釋嗎? –

+0

抱歉,你能解釋一下這個..所觀察到的模式是否正確? –