0

I am using MLE and l-moments method for gamma distribution, exponential distribution and weibull distribution.

I used fitdistr() in gamma distribution.

I have an error messga saying that L-BFGS-B needs finite values of 'fn' And I wonder if I can fix this by change the optimization method from L-BFGS-B to BFGS.

Error in stats::optim(x = c(36.576, 1.778, 30.48, 1.524, 21.336, 3.302, : L-BFGS-B needs finite values of 'fn'

Here's my code.

# Maximum Likelihood Estimator (MLE)
  gams_mle <- fitdistr(month_temp, "gamma",  list(shape = s_gam, rate = 1/g_gam), lower = c(0,0))
  gam_mle <- c(as.numeric(gams_mle$estimate[1]), as.numeric(gams_mle$estimate[2]))

Sample data:

0 1972 4 4 4.318 2

1 1972 4 4 6.604 4

2 1972 4 4 3.302 6

3 1972 4 4 0.762 8

4 1972 5 5 0.254 10

5 1972 5 5 3.048 12

6 1972 5 5 0.254 14

7 1972 5 5 1.778 16

8 1972 5 5 0.254 18

9 1972 5 5 1.778 20

10 1972 5 5 0.762 22

and in my main file, see the code below:

# 2. Gamma distribution function (alpha, beta)
j = 13
for (i in 1:12){
  month_temp = input_data[,3]
  index = month_temp == i
  month_temp = input_data[index,5] 

  par_gam = gamma_fit(month_temp, option = FALSE)
  par_matrix[j,1] = i
  par_matrix[j,2] = 2
  par_matrix[j, 3:4] = par_gam[1:2]
  par_matrix[j, 8:9] = par_gam[3:4]
  j = j + 1     
 }
Tung
  • 26,371
  • 7
  • 91
  • 115
JDDD
  • 61
  • 2
  • 2
  • 7
  • 1
    Can you provide data so that we can reproduce the error? – Dan Jun 29 '18 at 15:06
  • Welcome to StackOverflow! For code debugging please always ask with a [reproducible](https://stackoverflow.com/q/5963269/1422451) example per the [MCVE](https://stackoverflow.com/help/mcve) and [`r`](https://stackoverflow.com/tags/r/info) tag description, with the desired output. – Hack-R Jun 29 '18 at 15:14
  • @Lyngbakr I provided partial data and I am not sure if its enough to reproduce the error. – JDDD Jun 29 '18 at 15:14

0 Answers0