[未知用户]
给你一个例子:
set.seed(123)
shape = 2
scale = 3
location = -1
x = rgamma(100, shape = shape, scale = scale) + location
negll = function(param, x)
{
shape = param[1]
scale = param[2]
location = param[3]
-sum(dgamma(x - location, shape = shape, scale = scale,
log = TRUE))
}
## shape > 0, scale > 0, location < min(x)
constrOptim(c(1, 1, min(x) - 0.1), f = negll, grad = NULL,
ui = rbind(c(1, 0, 0),
c(0, 1, 0),
c(0, 0, -1)),
ci = c(0, 0, -min(x)),
x = x)