0

在 中mle2,我使用“optimx”作为优化器。我想对参数使用下限和上限。我怎样才能做到这一点?

例如:

 library("bbmle"); library("optimx")
 y <- c(0.654, 0.613, 0.315, 0.449, 0.297, 0.402, 0.379,
        0.423, 0.379, 0.3235, 0.269, 0.740, 0.418, 0.412, 
        0.494, 0.416, 0.338, 0.392, 0.484, 0.265) 
 gamma4 <- function(shape, scale) {
  -sum(dgamma(y, shape = shape, scale = scale,log = TRUE))
 } 
 gm <- mean(y) 
 cv <- var(y)/mean(y) 
 m5 <- mle2(gamma4,start = list(shape = gm/cv, scale = cv),
            optimizer="optimx") 
 m5

或者:

  mle2(gengamma3,start = list(shape = ci, 
      scale = bet, k=alp),
      optimizer="optimx")

谢谢

4

1 回答 1

1

您可以尝试将较低的函数编写为最后一个参数,如下例所示:

## use bounded optimization
## the lower bounds are really > 0, but we use >=0 to stress-test
## profiling; note lower must be named
(fit1 <- mle2(LL, method="L-BFGS-B", lower=c(ymax=0, xhalf=0)))
p1 <- profile(fit1)

或者在那一个:

# try bounded optimization with nlminb and constrOptim
(fit1B <- mle2(LL, optimizer="nlminb", lower=c(lymax=1e-7, lhalf=1e-7)))
p1B <- profile(fit1B)
confint(p1B)
(fit1C <- mle2(LL, optimizer="constrOptim", ui = c(lymax=1,lhalf=1), ci=2,
   method="Nelder-Mead"))

但为了充分理解,我建议看这里

于 2015-11-08T00:06:30.247 回答