# [R] maximizing the gamma likelihood

From: <markleeds_at_verizon.net>
Date: Fri, 23 May 2008 16:28:25 -0500 (CDT)

f(y_i) = (1/gammafunction(shape)) * (scale^shape) * (y_i^(shape-1)) * exp(-scale*y_i)

( i'm defining the scale as lambda rather than 1/lambda. various books
define it differently ).

i found the likelihood to be n*shape*log(scale) +
(shape-1)*sum(log(y_i) - scale*sum(y_i)
then i wrote below which is just roger peng's likelihood example but using the gamma instead of the normal.
I get estimates back but i separately found that the analytical mle of the scale is equal to 1/ analytical mle(shape). and my estimates aren't consistent with that fact ? this leads me to assume that my estimates are not correct.

can anyone tell me what i'm doing wrong. maybe my starting values are too far off ? thanks.

make.negloglik <- function(data, fixed=c(FALSE,FALSE)) {

op <- fixed
function(p) {

```     op[!fixed] <- p
shape <- exp(op[1])
scale <- exp(op[2])
a <- length(data)*shape*log(scale)
b <- (shape-1)*sum(log(data))
c <- -1.0*scale*sum(data)
-(a + b + c)
```

}
}

vsamples<- c(14.7, 18.8, 14, 15.9, 9.7, 12.8) nLL <- make.negloglik(vsamples)
temp <- optim(c(scale=1,shape=1), nLL, method="BFGS")[["par"]] estimates <- log(temp)
print(estimates)

check <- estimates[1]/mean(vsamples)
print(check)

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 23 May 2008 - 21:30:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 24 May 2008 - 07:30:43 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.