R optim()L-BFGS-B需要'fn'的有限值

时间:2018-06-29 14:42:16

标签: r gamma-distribution fitdistrplus

我正在使用MLE和l矩方法进行伽马分布,指数分布和魏布尔分布。

我在伽玛分布中使用了fitdistr()。

我有一个错误消息,说L-BFGS-B需要'fn'的有限值 我想知道是否可以通过将优化方法从L-BFGS-B更改为BFGS来解决此问题。

  

stats :: optim(x = c(36.576,1.778,30.48,1.524,21.336,3.302,:     L-BFGS-B需要有限的'fn'

这是我的代码。

# 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]))

样本数据:

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

在我的主文件中,请参见以下代码:

# 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     
 }

0 个答案:

没有答案
相关问题