mle 无法估计参数,错误代码为 7

mle failed to estimate the parameters with the error code 7

我正在尝试估计 Weibull-Gamma 分布参数,但遇到以下错误:

"the function mle failed to estimate the parameters, with the error code 7"

我该怎么办?

Weibull-Gamma 分布

密度函数

dWeibullGamma <- function(x, alpha, beta, lambda) 
{
  ((alpha*beta)/(lambda))*(x^(alpha-1))*(1+(1/lambda)*x^(alpha))^(-(beta+1))
}

累积分布函数

   pWeibullGamma <- function(x, alpha, beta, lambda) 
{
  1-(1+(1/lambda)*x^(alpha))^(-(beta))
}

风险函数

hWeibullGamma <- function(x, alpha, beta, lambda) 
{
((alpha*beta)/(lambda))*(x^(alpha-1))*(1+(1/lambda)*x^(alpha))^(-(beta+1))/(1+(1/lambda)*x^(alpha))^(-(beta)) 
}

生存函数

sWeibullGamma <- function(x,alpha,beta,lambda)
{
  (1+(1/lambda)*x^(alpha))^(-(beta))
}

估计值

paramWG = fitdist(data = dadosp, distr = 'WeibullGamma', start = c(alpha=1.5,beta=1,lambda=1.5), lower= c(0, 0))
summary(paramWG) 

Sample: 

dadosp = c(240.3,71.9,271.3, 186.3,241,253,287.4,138.3,206.9,176,270.4,73.3,118.9,203.1,139.7,31,269.6,140.2,205.1,133.2,107,354.6,277,27.6,186,260.9,350.4,242.6,292.5, 112.3,242.8,310.7,309.9,53.1,326.5,145.7,271.5, 117.5,264.7,243.9,182,136.7,103.8,188.3,236,419.8,338.6,357.7)

对于您的样本,算法在估计 ML 时没有收敛。将 Weibull-Gamma 分布拟合到此数据需要极高的 lambda 值。你可以通过估计 log10(lambda) 而不是 lambda.

来解决这个问题

您可以在您的 4 个函数中添加 lambda <- 10^lambda,例如

dWeibullGamma <- function(x, alpha, beta, lambda) 
{
  lambda <- 10^lambda
  ((alpha*beta)/(lambda))*(x^(alpha-1))*(1+(1/lambda)*x^(alpha))^(-(beta+1))
}

然后,算法似乎收敛了:

library(fitdistrplus)
paramWG = fitdist(data = data, distr = 'WeibullGamma',
                  start = list(alpha=1, beta=1, lambda=1), lower = c(0, 0, 0))
summary(paramWG)$estimate

输出:

     alpha       beta     lambda 
  2.432939 799.631852   8.680802 

我们看到 lambda 的估计是 10^8.68,因此在不取对数时会出现收敛问题。

你也可以看看合身度如下:

newx <- 0:500
pars <- summary(paramWG)$estimate
pred <- dWeibullGamma(newx, pars["alpha"], pars["beta"], pars["lambda"])

hist(data, freq = FALSE)
lines(newx, pred, lwd = 2)

注意:也许拟合另一个分布会更有意义?