[R] Optimization max likelihood problem

Alaa Sindi alaasindi at gmail.com
Wed Apr 6 20:31:25 CEST 2016


hello all,

I am getting wrong estimates from this code. do you know what could be the problem. 

thanks


x<- c(1.6, 1.7, 1.7, 1.7, 1.8, 1.8, 1.8, 1.8)
y <- c( 6, 13, 18, 28, 52, 53, 61, 60)
n <- c(59, 60, 62, 56, 63, 59, 62, 60)

DF <- data.frame(x, y, n)

# note: there is no need to have the choose(n, y) term in the likelihood
fn <- function(p, DF) {
  z <- p[1]+p[2]*DF$x
  sum( - (DF$y*z) - DF$n*log(1+exp(z)))
  
  #sum( - (y*(p[1]+p[2]*x) - n*log(1+exp(p[1]+p[2]*x))) )
}
out <- nlm(fn, p = c(1,1),DF, hessian = TRUE, print.level=2)
print(out)
eigen(out$hessian)


More information about the R-help mailing list