Weibull Distribution parameter estimation error

雨燕双飞 提交于 2020-01-06 08:28:13

问题


I used the following function to estimate the three-parameter Weibull distribution.

library(bbmle)
library(FAdist)
set.seed(16)
xl=rweibull3(50, shape = 1,scale=1, thres = 0)
dweib3l <- function(shape, scale, thres) { 
  -sum(dweibull3(xl , shape, scale, thres, log=TRUE))
}
ml <- mle2(dweib3l, start= list(shape = 1, scale = 1, thres=0), data=list(xl))

However, when I run the above function I am getting the following error.

Error in optim(par = c(shape = 1, scale = 1, thres = 0), fn = function (p)  : 
  non-finite finite-difference value [3]
In addition: There were 16 warnings (use warnings() to see them)

Is there any way to overcome this issue? Thank you!


回答1:


The problem is that the threshold parameter is special: it defines a sharp boundary to the distribution, so any value of thres above the minimum value of the data will give zero likelihoods (-Inf negative log-likelihoods): if a given value of xl is less than the specified threshold, then it's impossible according to the statistical model you have defined. Furthermore, we know already that the maximum likelihood value of the threshold is equal to the minimum value in the data set (analogous results hold for MLE estimation of the bounds of a uniform distribution ...)

I don't know why the other questions on SO that address this question don't encounter this particular problem - it may be because they use a starting value of the threshold that's far enough below the minimum value in the data set ...

Below, I use a fixed value of min(xl)-1e-5 for the threshold (shifting the value downward avoids numerical problems when the value is exactly on the boundary). I also use the formula interface so we can call the dweibull3() function directly, and put lower bounds on the shape and scale parameters (as a result I need to use method="L-BFGS-B", which allows for constraints).

ml <- mle2(xl ~ dweibull3(shape=shape, scale = scale,
                        thres=min(xl)-1e-5),
           start=list(shape=1, scale=1),
           lower=c(0,0),
           method="L-BFGS-B",
           data=data.frame(xl))

(The formula interface is convenient for simple examples: if you want to do something very much more complicated you may want to go back to defining your own log-likelihood function explicitly.)


If you insist on fitting the threshold parameter, you can do it by setting an upper bound that is (nearly) equal to the minimum value that occurs in the data [any larger value will give NA values and thus break the optimization]. However, you will find that the estimate of the threshold parameter always converges to this upper bound ... so this approach is really getting to the previous answer the hard way (you'll also get warnings about parameters being on the boundary, and about not being able to invert the Hessian).

eps <- 1e-8
ml3 <- mle2(xl ~ dweibull3(shape=shape, scale = scale, thres = thres),
            start=list(shape=1, scale=1, thres=-5),
            lower=c(shape=0,scale=0,thres=-Inf),
            upper=c(shape=Inf,scale=Inf,thres=min(xl)-eps),
            method="L-BFGS-B",
            data=data.frame(xl))

For what it's worth it does seem to be possible to fit the model without fixing the threshold parameter, if you start with a small value and use Nelder-Mead optimization: however, it seems to give unreliable results.



来源:https://stackoverflow.com/questions/55386447/weibull-distribution-parameter-estimation-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!