[R] help in maximum likelihood

Alaa Sindi alaasindi at icloud.com
Tue Mar 1 21:09:09 CET 2016


Hi all,

what is wrong with this code? I am trying to estimate the model parameters by maximizing the likelihood function and I am getting this warning 


Warning message:
In nlm(fn, p = c(-50, 20), hessian = TRUE) :
  NA/Inf replaced by maximum positive value




x <- c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610, 1.8839)
y <- c( 6, 13, 18, 28, 52, 53, 61, 60)
n <- c(59, 60, 62, 56, 63, 59, 62, 60)
fn <- function(p)
    sum( - (y*(p[1]+p[2]*x) - n*log(1+exp(p[1]+p[2]*x))
            + log(choose(n, y)) ))
out <- nlm(fn, p = c(-50,20), hessian = TRUE)


Thanks


More information about the R-help mailing list