[英]Goodness of fit test for power law distribution in R
I have a network for which I fit into a power-law using igraph software: 我有一个网络,可以使用igraph软件将其纳入幂律规则:
plf = power.law.fit(degree_dist, impelementation = "plfit")
The plf variable now holds the following variables: 现在,plf变量包含以下变量:
$continuous
[1] TRUE
$alpha
[1] 1.63975
$xmin
[1] 0.03
$logLik
[1] 4.037563
$KS.stat
[1] 0.1721117
$KS.p
[1] 0.9984284
The igraph manual explains these variables: igraph手册解释了以下变量:
xmin = the lower bound for fitting the power-law
alpha = the exponent of the fitted power-law distribution
logLik = the log-likelihood of the fitted parameters
KS.stat = the test statistic of a Kolmogorov-Smirnov test that compares the fitted distribution with the input vector. Smaller scores denote better fit
KS.p = the p-value of the Kolmogorov-Smirnov test. Small p-values (less than 0.05) indicate that the test rejected the hypothesis that the original data could have been drawn from the fitted power-law distribution
I would like to do a "goodness of fit" test on this power law fit. 我想对此幂律拟合进行“拟合优度”检验。 But I am not sure how to do this, and although I found this question already asked in online forums, it usually remains unanswered.
但是我不确定如何执行此操作,尽管我发现在线论坛中已经问过这个问题,但通常仍然没有答案。
I think one way to do this would be to do a chisq.test(x,y). 我认为执行此操作的一种方法是执行chisq.test(x,y)。 One input parameter (say x) would be the degree_dist variable (the observed degree distribution of the network).
一个输入参数(例如x)将是degree_dist变量(观察到的网络度分布)。 The other input parameter (say y) would be the fitted power law equation, which is supposed to be of form P(k) = mk^a.
另一个输入参数(例如y)将是拟合的幂律方程,假定其形式为P(k)= mk ^ a。
I am not sure whether this is a sound approach, and if so, I need advice on how to construct the fitted power law equation. 我不确定这是否是一种合理的方法,如果是,我需要有关如何构造拟合幂律方程的建议。
In case it helps, the degree_dist of my network was: 如果有帮助,我的网络的degree_dist为:
0.00 0.73 0.11 0.05 0.02 0.02 0.03 0.02 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.01 0.00 0.00 0.00 0.01
(These are frequencies that degrees of 0-21 occurred in the network. (For example, 73% of nodes has degree 1, 1% of nodes had degree 21). (这些频率在网络中发生0-21度。(例如,73%的节点具有1级,1%的节点具有21级)。
** * ** * *** ** * ** * *** EDIT
编辑 ** * ** * ** * ****
** * ** * ** * ****
I am unsure whether it was a mistake above to use degree_dist to calculate plf. 我不确定使用degree_dist计算plf是否在上面。 In case it is, I also ran the same function using the degrees from the 100 nodes in my network:
如果是这样,我还使用网络中100个节点的度数运行了相同的函数:
plf = power.law.fit(pure_deg, impelementation = "plfit")
where, pure_deg is: 其中,pure_deg是:
21 7 5 6 17 3 6 6 2 5 4 3 7 4 3 2 2 2 2 3 2 3 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
This leads to output of: 这导致输出:
$continuous
[1] FALSE
$alpha
[1] 2.362445
$xmin
[1] 1
$logLik
[1] -114.6303
$KS.stat
[1] 0.02293443
$KS.p
[1] 1
There is a package named powerRlaw in R by Colin Gillespie. Colin Gillespie在R中有一个名为powerRlaw的软件包。 This package is well documented and contains a lot of example to use each function.
该软件包文档齐全,并包含许多使用每个函数的示例。 Very straightforward.
非常简单。
http://cran.r-project.org/web/packages/poweRlaw/ http://cran.r-project.org/web/packages/poweRlaw/
For example in R as the documentation said, the following code get data from the file full_path_of_file_name and estimate xmin and alpha and get p-value as proposed by Clauset and al. 例如,在R作为文档所述,下面的代码获得从文件full_path_of_file_name和估计XMIN和α的数据和所提议得到p值Clauset和人。 (2009)
(2009年)
library("poweRLaw")
words = read.table(<full_path_of_file_name>)
m_plwords = displ$new(words$V1) # discrete power law fitting
est_plwords = estimate_xmin(m_plwords) # get xmin and alpha
# here we have the goodness-of-fit test p-value
# as proposed by Clauset and al. (2009)
bs_p = bootstrap_p(m_plwords)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.