rdistributionfitdistrplus

Error in fitdist function: the function mle failed to estimate the parameters, with the error code 1 (Rayleigh distribution)


I am trying to fit my data to Rayleigh distribution by using the fitdist function from the fitdistrplus package.

x <- c(19.000000,23.000000,26.000000,45.000000,8.050000,46.900000,1.268333,30.000000,
       1.466667,3.733333,1.683333,4.000000,3.950000,1.850000,42.000000,1.333333,
       1.550000,1.000000,2.066667,1.566667,1.216667,1.850000,1.400000,8.366667,
       19.000000,29.000000,17.000000,42.000000,19.000000,10.000000,53.000000,2.550000,
       15.483333,1.533333,1.216667,1.550000,32.000000,6.583333,6.516667,5.750000,
       9.283333,46.000000,2.016667,2.133333,4.516667,46.950000,1.600000,1.433333,
       3.166667,4.416667,17.016667,2.433333,2.713333,8.633333,3.150000,1.183333,
       14.000000,10.706667,7.026944,31.000000,35.000000,21.000000,14.000000,2.200000,
       26.000000,3.316667,51.000000,13.000000,34.000000,11.650000,49.000000,12.000000,
       26.000000,20.000000,22.000000,6.483333,24.000000,5.333333,4.833333,8.750000,
       6.216667,17.000000,1.083333,19.000000,48.000000,15.000000,1.266667,54.000000,
       32.000000,3.616667,6.666667,1.600000,2.083333,6.933333,33.033333,1.883333,
       1.000000,3.072222,49.000000,1.400000)
dat <- data.frame(x)

# Generate gamma rvs
den <- density(x)
orig <- data.frame(x = den$x, y = den$y)

fit.params.2 <- fitdistrplus::fitdist(dat$x, "rayleigh", start = list(sigma = 1))

Then an error occurs:

Error in fitdistrplus::fitdist(dat$x, "rayleigh", start = list(sigma = 1)) : 
   the function mle failed to estimate the parameters, 
                with the error code 1

Is there any solution to this problem? Thanks for any help.


Solution

  • There are two problems. (1) the Rayleigh distribution does not seem to be a good fit to the data (see plot output below) and (2) you need a better starting value. Since sigma is proportional to the mean for the Rayleigh distribution (see wikipedia) try that:

    library(fitdistrplus)
    library(extraDistr)
    
    fit <- fitdist(dat$x, "rayleigh", start = list(sigma = mean(dat$x)))
    fit
    ## Fitting of the distribution ' rayleigh ' by maximum likelihood 
    ## Parameters:
    ##       estimate Std. Error
    ## sigma 15.00063   0.749935
    
    plot(fit)
    

    screenshot