【发布时间】:2021-09-08 11:38:17
【问题描述】:
我尝试使用 mle 来估计负二项分布的参数。这是我的代码。
library(stats4)
library(bbmle)
library(MASS)
b=rnbinom(n=1000, size=3, prob=0.1)
LL2 <- function(size, prob) {
R = dnbinom(b, size, prob, log = TRUE)
-sum(R)
}
当我将 mle 函数设置为下限和上限时,我得到了
stats4::mle(LL2, start = list(size = 3, prob = 0.1),lower = c(-Inf,-Inf),upper = c(Inf,Inf))
Error in optim(start, f, method = method, hessian = TRUE, lower = lower, :
L-BFGS-B needs finite values of 'fn'
当我移除边界时
stats4::mle(LL2, start = list(size = 3, prob = 0.1))
Call:
stats4::mle(minuslogl = LL2, start = list(size = 3, prob = 0.1))
Coefficients:
size prob
3.0467857 0.1037522
但是,如果我将边界更改为有限值,错误仍然存在。
我想知道为什么会这样?是不是因为 L-BFGS-B 方法无法处理边界设置?
我们将不胜感激。
【问题讨论】:
-
将边界设置为
-Inf到Inf的意义何在 - 这与无边界相同。 -
你尝试了哪些有限值?
标签: r statistics distribution mle