尝试使用fitdistr来拟合R中的泊松分布到Ergraph中构造的Erdos.Renyi随机图

时间:2014-11-21 23:05:01

标签: r poisson

在R中使用igraph,我试图证实构建随机网络的Erdos-Reyni方法确实最终得到了具有与Poisson分布非常吻合的度分布的网络。所以,我运行了R代码:

library(igraph)

library(MASS) #for fitdistr function

samples<-5000

# first n is the number of nodes, the n/samples is the probability of making 
# an edge between any two nodes
g <- erdos.renyi.game(samples, 20/ samples)  

d <- degree(g) #finds the degree of each node in graph

# fit should be done on frequency, not on probability, and not on summary
fits<-fitdistr(d,"Poisson") 

dd<- as.numeric(table(d)) # creates a summary of each degree and its frequency

plot(dd, xlab = "degree", ylab="frequency") # plot degree distribution

a<-1:length(dd)

# multiply by original samples to create frequency plots
lines(a,dpois(a,lambda=fits$estimate)* samples) 

enter image description here

我得到一个图,其中看起来度数的分布确实是泊松,但是与实际度分布相比,最佳拟合泊松分布显着右移。假设创建图表使得每个节点平均有20个链接,那么最合适的lambda值大约为20是有道理的,但为什么实际分布的模式大约为14(尽管度数的平均值是也大约20)?

0 个答案:

没有答案