gpt4 book ai didi

r - R 中幂律分布的拟合优度检验

转载 作者:行者123 更新时间:2023-12-04 02:31:02 25 4
gpt4 key购买 nike

我有一个网络,我使用 igraph 软件符合幂律:

plf = power.law.fit(degree_dist, impelementation = "plfit")

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

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

我想对这个幂律拟合做一个“拟合优度”检验。但我不确定该怎么做,虽然我发现这个问题已经在在线论坛上提出,但通常没有人回答。

我认为一种方法是执行 chisq.test(x,y)。一个输入参数(比如 x)将是 degree_dist 变量(观察到的网络度分布)。另一个输入参数(比如 y)是拟合的幂律方程,其形式应该是 P(k) = mk^a。

我不确定这是否是一种合理的方法,如果是这样,我需要有关如何构建拟合幂律方程的建议。

如果有帮助,我网络的 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

(这些是网络中出现度数 0-21 的频率。(例如,73% 的节点具有度数 1,1% 的节点具有度数 21)。

********* 编辑 *************

我不确定上面使用 degree_dist 计算 plf 是否是一个错误。如果是这样,我还使用网络中 100 个节点的度数运行相同的函数:

plf = power.law.fit(pure_deg, impelementation = "plfit")

其中,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

这导致输出:

$continuous
[1] FALSE
$alpha
[1] 2.362445
$xmin
[1] 1
$logLik
[1] -114.6303
$KS.stat
[1] 0.02293443
$KS.p
[1] 1

最佳答案

Colin Gillespie 在 R 中有一个名为 powerRlaw 的包。这个包有很好的文档,包含很多使用每个功能的例子。非常简单。

http://cran.r-project.org/web/packages/poweRlaw/

例如,如文档所述,在 R 中,以下代码从文件 full_path_of_file_name 获取数据并估计 xmin 和 alpha,并按照 Clauset and al. (2009) 的建议获取 p 值

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)

关于r - R 中幂律分布的拟合优度检验,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21541240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com