Hi Kate! On Fri, Mar 12, 2010 at 6:20 AM, kate <yh...@illinois.edu> wrote: > Hi R-users, > > Recently, I use maxNR function to find maximizer. I have error appears as > follows > Error in maxNRCompute(fn = fn, grad = grad, hess = hess, start = start, : > NA in the initial gradient > > My code is > > mu=2 > s=1 > n=300 > library(maxLik) > set.seed(1004) > x<-rcauchy(n,mu,s) > loglik<-function(mu) > { > log(prod(dcauchy(x,mu,s))) > } > maxNR(loglik,start=median(x))$estimate > > > Does anyone know how to solve this problem?
Yes :-) Algebraically, "log(prod(z))" is equal to "sum(log(z))" but these two expressions might return different numbers on digital computers: R> ll<-function(mu) { sum(log(dcauchy(x,mu,s))) } R> ll(2) [1] -754.4928 R> loglik(2) [1] -Inf R> maxNR(ll,start=median(x))$estimate [1] 2.075059 Best wishes from Copenhagen, Arne -- Arne Henningsen http://www.arne-henningsen.name ______________________________________________ R-help@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.