如何在R中绘制度分布 [英] how to plot degree distribution in R

查看:351
本文介绍了如何在R中绘制度分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to know whether the output of a script to plot a degree distribution can be correct.

因此脚本是(其中所有顶点的向量都存储在x中):

So the script is ( where the vector with the degrees of all my vertices is stored in 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)

x is the degree of a certain network vertice - like vertice 1 has degree 7, vertice 2 has degree 9 and so on 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)

我的问题是日志plot似乎是不正确的-例如,我的整体得分为'7'8倍,所以对数对数图上的这一点不应变成0.845(log 7)/ 0.903(log(8)像(x / y )?

My problem is that the log-log plot seems to be incorrect - for instance, I have the degree '7' 8 times overall so shouldn't this point on a log-log plot become 0.845 (log 7)/ 0.903 (log(8) as in (x/y)?

此外,有人可以告诉我如何将线(对数对数刻度上的幂律)拟合到屏幕2中的图吗?

Moreover, can somebody tell me how to fit the line ( the power-law on the log-log scale) to the plot in the screen 2 ?

推荐答案

我对 igraph 包不熟悉,所以您不能帮忙吗那个特定的包裹。但是,这是一些用于在对数-对数图上绘制分布的代码。首先是一些数据:

I'm not familar with the igraph package, so can't you help with that specific package. However, here is some code for plotting distributions on the log-log plot. First some data:

set.seed(1)
x = ceiling(rlnorm(1000, 4))

然后我们需要重新排列以获取逆CDF:

Then we need to rearrange the to get the inverse 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,而您正在执行简单的线性回归(不推荐)。

Regarding your fitting question, I think the discrepancy arises because igraph uses the MLE whereas you are doing simple linear regression (which is not recommended).

作为一个插件,我已经开始使用 package 用于拟合和绘制幂律。因此,使用此软件包,您将得到:

As a bit of a plug, I've started work on a package for fitting and plotting powerlaws. So, using this package you get:

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)

这篇关于如何在R中绘制度分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆