【问题标题】:Get wrong answer when doing MLE on gamma parameters对伽玛参数进行 MLE 时得到错误答案
【发布时间】:2018-10-04 15:13:55
【问题描述】:

我首先要采样 100 个 gamma 分布的数字,其中 shape = 2 且 scale = 1/2。我写下了对数似然函数并否定了它,因为我正在使用最小化工具来最大化。我也尝试使用optim,但无济于事。 optimnlm 都给了我不同的答案。到目前为止,这是我的代码:

N = 100
shape = 2     
scale = 1/2   
Data <- rgamma(SampSize, shape, scale)

LogL = function (x){
  k     = x[1]
  gamma = x[2]
  (-1)*(N*x[1]*log(x[2])+(x[1]-1)*sum(log(Data))-x[2]*sum(Data))   
}
nlm(LogL,c(1.5,1))

【问题讨论】:

  • 成功了,非常感谢!但是,您能解释一下为什么我的方法不起作用吗?编辑:确实我后来意识到了!

标签: r mle


【解决方案1】:
logL <- function (x) -sum(dgamma(Data, x[1], x[2], log = TRUE))

N = 100
shape = 2     
scale = 1/2   
Data <- rgamma(N, shape, scale)

optim(c(1.5, 1), logL)$par
nlm(logL, c(1.5, 1))$estimate

【讨论】:

  • 谢谢。请问,一旦我使用 nlm,我怎样才能访问这些估计值?它们存储在哪里?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-25
  • 1970-01-01
  • 1970-01-01
  • 2020-01-06
  • 2017-05-20
  • 2019-05-06
  • 1970-01-01
相关资源
最近更新 更多