Solve for maximum likelihood with two parameters under constraints

佐手、 提交于 2019-12-06 12:58:15

By default, optim will minimize, but you want to maximize LL. Also, you want to use a method like L-BFGS-B, which uses bound information:

optim(c(1, 1), function(x) -LL(x[1], x[2], n=n, t=t), method="L-BFGS-B",
      lower=c(0.0001, 0.0001))
# $par
# [1]    0.0001 9679.3562
# 
# $value
# [1] 17075.64
# 
# $counts
# function gradient 
#       87       87 
# 
# $convergence
# [1] 0
# 
# $message
# [1] "CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH"

We can verify we've improved the log-likelihood:

LL(1, 1, n=n, t=t)
# [1] -27659.45

LL(0.0001, 9679.3562, n=n, t=t)
# [1] -17075.64
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!