Reputation: 21
I'm trying to fit a numeric vector with the fitdist() function (included in fitdistrplus package) to several distributions: weibull 2-P, weibull 3-P, gamma, lognormal, exponential, gumbel, normal, loglogistic, logistic, and generalized lambda.
Some of them are included in the same package that 'fitdist()', others are included in different packages, and I create gumbel distribution. I have no problem with any of them, only with the GLD. I've tried all the methods of the fitdist function (mle, mme...), and the packages "gld" and "GLDEX" to create the distribution function.
fitdist(example$`TTF MIN`, "gl", start=list(12139.06, 0.000434674, 0.2, -1.5), method="mle", control=list(trace=1, REPORT=1))
Error in fitdist(example$`TTF MIN`, "gl", start = list(12139.06, 0.000434674, :
the function mle failed to estimate the parameters,
with the error code 100
And...
memp <- function(x, order) mean(x^order)
fgl <- fitdist(example$`TTF MIN`, "gl", method="mme",order=c(1, 2, 3, 4), memp="memp", start=c(10, 10), lower=1, upper=Inf)
Error in mmedist(data, distname, start = start, fix.arg = fix.arg, ...) :
wrong dimension for the moment order to match
Data basic statistics:
min(example$`TTF MIN`)
[1] 1338.149
max(example$`TTF MIN`)
[1] 27485.42
median(example$`TTF MIN`)
[1] 12555.87
mean(example$`TTF MIN`)
[1] 13983.5
sd(example$`TTF MIN`)
[1] 4220.227
skewness(example$`TTF MIN`)
[1] 0.7572039
kurtosis(example$`TTF MIN`)
[1] -0.1358661
quantile(example$`TTF MIN`, probs = c(0.25, 0.5, 0.75, 1))
25% 50% 75% 100%
11006.06 12555.87 17037.58 27485.42
Upvotes: 2
Views: 896
Reputation: 24272
The problem that you find with fitdist
and the generalized lambda distribution (GLD) seems to be due to the optmization algorithm implemented in the command.
If we estimate the parameters of the GLD using the fit.fkml
command of gld
we get the optimal values with no errors:
library(fitdistrplus)
library(gld)
set.seed(3)
x <- rnorm(100, mean=2, sd=3)
fitGLD <- fit.fkml(x, method = "ML")
print(fitGLD)
########
Maximum Likelihood estimate, gld type: fkml
lambda1 lambda2 lambda3 lambda4
2.2351 0.4406 0.2643 0.4115
Below we try to estimate the GLD parameters using fitdist
and using initial values of the parameters that are not far from the optimal values given by fit.fkml
:
fitdist(x, "gl", start=list(2.2,0.4,0.3,0.5), method="mle",
control=list(trace=1, REPORT=1))
######
Nelder-Mead direct search function minimizer
<simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data, gr = gradient, ddistnam = ddistname, hessian = TRUE, method = meth, lower = lower, upper = upper, ...): la funzione non può essere calcalata per i parametri iniziali>
Error in fitdist(x, "gl", start = list(2.0, 0.4, 0.3, 0.5), method = "mle", :
the function mle failed to estimate the parameters,
with the error code 100
The algorithm fails to find a solution, but if we retry with initial values that are closer to the optimal ones, fitdist
yields a solution:
optGLD <- fitGLD$optim.results$par
(opt <- round(optGLD ,1))
#######
[1] 2.2 0.4 0.3 0.4
fitdist(x, "gl", start=list(opt[1], opt[2], opt[3], opt[4]), method="mle",
control=list(trace=0, REPORT=1))
########
Fitting of the distribution ' gl ' by maximum likelihood
Parameters:
estimate Std. Error
1 2.2369295 0.31415154
2 0.4407676 0.05857841
3 0.2639203 0.07714630
4 0.4115397 0.09449990
Upvotes: 0