rplcon()
我使用包中的函数生成一些随机变量poweRlaw
data <- rplcon(1000,10,2)
现在,我想知道哪些已知分布最适合数据。对数规范?经验?伽玛?幂律?指数截止的幂律?
所以我fitdist()
在包中使用函数fitdistrplus
:
fit.lnormdl <- fitdist(data,"lnorm")
fit.gammadl <- fitdist(data, "gamma", lower = c(0, 0))
fit.expdl <- fitdist(data,"exp")
由于幂律分布和指数截止的幂律不是根据CRAN 任务视图:概率分布的基本概率函数,所以我根据示例 4 编写幂律的 d,p,q 函数?fitdist
dplcon <- function (x, xmin, alpha, log = FALSE)
{
if (log) {
pdf = log(alpha - 1) - log(xmin) - alpha * (log(x/xmin))
pdf[x < xmin] = -Inf
}
else {
pdf = (alpha - 1)/xmin * (x/xmin)^(-alpha)
pdf[x < xmin] = 0
}
pdf
}
pplcon <- function (q, xmin, alpha, lower.tail = TRUE)
{
cdf = 1 - (q/xmin)^(-alpha + 1)
if (!lower.tail)
cdf = 1 - cdf
cdf[q < round(xmin)] = 0
cdf
}
qplcon <- function(p,xmin,alpha) alpha*p^(1/(1-xmin))
最后,我使用下面的代码来获取参数xmin
和alpha
幂律:
fitpl <- fitdist(data,"plcon",start = list(xmin=1,alpha=1))
但它会抛出一个错误:
<simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data, ddistnam = ddistname, hessian = TRUE, method = meth, lower = lower, upper = upper, ...): function cannot be evaluated at initial parameters>
Error in fitdist(data, "plcon", start = list(xmin = 1, alpha = 1)) :
the function mle failed to estimate the parameters,
with the error code 100
我尝试在google和stackoverflow中搜索,出现了很多类似的错误问题,但是在阅读和尝试之后,我的问题没有解决方案,我应该怎么做才能正确完成以获得参数?感谢所有帮助我的人!