[R] warning message in nlm

Spencer Graves spencer.graves at pdf.com
Thu Oct 5 16:27:11 CEST 2006


      Without 'msc39', I can't say for sure, but I doubt if it's 
anything to worry about.  It looks like 'nlm' tests values for theta and 
len that produce either NA or Inf in computing 'loglikcs'.  Since you 
got an answer, it does not look to me like it's anything worth worrying 
about;  just make sure you are minimizing (-log(likelihood)), not 
maximizing it.  For more detail, you can run 'nlm' with print.level = 2 
rather than the default of 0 -- and make contour plots of loglikcs in an 
appropriate region of the optimum, as suggested in Venables and Ripley 
(2002) Modern Applied Statistics with S (Springer), discussing 
'expand.grid' and 'contour'. 

      Hope this helps. 
      Spencer Graves

singyee ling wrote:
> Dear R-users,
>
> I am trying to find the MLEs for a loglikelihood function (loglikcs39) and
> tried using both optim and nlm.
>
> fredcs39<-function(b1,b2,x){return(exp(b1+b2*x))}
> loglikcs39<-function(theta,len){
> sum(mcs39[1:len]*fredcs39(theta[1],theta[2],c(8:(7+len))) - pcs39[1:len] *
> log(fredcs39(theta[1],theta[2],c(8:(7+len)))))
> }
> theta.start<-c(0.1,0.1)
>
>
> 1. The output from using optim is as follow
> --------------------------------------------------------------
>
> optcs39<-optim(theta.start,loglikcs39,len=120,method="BFGS")
>   
>> optcs39
>>     
> $par
> [1] -1.27795226 -0.03626846
>
> $value
> [1] 7470.551
>
> $counts
> function gradient
>      133       23
>
> $convergence
> [1] 0
>
> $message
> NULL
>
> 2. The output from using nlm is as follow
> -----------------------------------------------------------
>
>   
>> outcs39<-nlm(loglikcs39,theta.start,len=120)
>>     
> Warning messages:
> 1: NA/Inf replaced by maximum positive value
> 2: NA/Inf replaced by maximum positive value
> 3: NA/Inf replaced by maximum positive value
> 4: NA/Inf replaced by maximum positive value
> 5: NA/Inf replaced by maximum positive value
> 6: NA/Inf replaced by maximum positive value
> 7: NA/Inf replaced by maximum positive value
>   
>> outcs39
>>     
> $minimum
> [1] 7470.551
>
> $estimate
> [1] -1.27817854 -0.03626027
>
> $gradient
> [1] -8.933577e-06 -1.460512e-04
>
> $code
> [1] 1
>
> $iterations
> [1] 40
>
>
> As you can see, the values obtained from using both functions are very
> similar.  But, what puzzled is the warning message that i got from using
> nlm. Could anyone please shed some light on how this warning message come
> about and whether it is a cause for concern?
>
>
> Many thanks in advance for any advice!
>
> singyee
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list