Trying to fit Poisson Distribution in R using fitdistr to Erdos.Reyni random graph constructed in Igraph

寵の児 提交于 2019-12-12 12:16:37

问题


Using igraph in R, I was trying to confirm that the Erdos-Reyni method of constructing random networks would indeed end up with networks with degree distributions that are well fit by a Poisson distribution. So, I ran the R the code:

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) 

I get a plot in which it looks like the distribution of degrees is indeed Poisson but the best fitting Poisson distribution is dramatically right shifted compared to the actual degree distribution. Given that the graph was created so that there would be on average 20 links per node, it makes sense that the best fitting lambda value is around 20, but why does the actual distribution have a mode around 14 (although the mean of the degrees is also around 20)?

来源:https://stackoverflow.com/questions/27071855/trying-to-fit-poisson-distribution-in-r-using-fitdistr-to-erdos-reyni-random-gra

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!