[R] How can I fixe convergence=1 in optim

David Winsemius dwinsemius at comcast.net
Sun Sep 5 04:15:42 CEST 2010


On Sep 4, 2010, at 4:18 PM, Sally Luo wrote:

> Hi R users,
>
> I am using the optim funciton to maximize a log likelihood  
> function.  My
> code is as follows:
>
> p<-optim(c(-0.2392925,0.4653128,-0.8332286,     0.0657, -0.0031,  
> -0.00245,
> 3.366, 0.5885, -0.00008,
>           0.0786,-0.00292,-0.00081, 3.266, -0.3632, -0.000049,     
> 0.1856,
> 0.00394, -0.00193, -0.889, 0.5379, -0.000063,
>           0.213, 0.00338, -0.00026, -0.8912, -0.3023, -0.000056), f,  
> method
> ="BFGS", hessian =TRUE, y=y,X=X,W=W)
> After I ran the code, I got the following results:
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> p
> $par
> [1]  2.235834e-02  1.282826e-01 -3.786014e-01  7.422526e-02   
> 3.037931e-02
> -2.570156e-03  3.365872e+00  2.618893e-01 -1.987859e-06
> [10]  7.970083e-02  2.878574e-03 -1.391019e-03  3.265966e+00  
> -4.153697e-01
> -3.185684e-03  1.833200e-01 -7.247683e-03 -3.156813e-03
> [19] -8.889219e-01  6.208612e-01  2.678643e-04  2.183787e-01   
> 2.715062e-02
> 2.943905e-04 -8.913260e-01 -5.100482e-01 -3.477559e-04
>
> $value
> [1] -932.1423
>
> $counts
> function gradient
>    1439      100
>
> $convergence
> [1] 1
> $message
> NULL
>
> $hessian  ( I omitted the approximation results for the hessian here  
> to save
> space)
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~ 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The error code 1 for convergence shown above means that the  
> iteration limit
> maxit had been reached.  How can I fix this problem and achieve  
> convergence
> for my optimization problem?  Can I increase the number of maxit so  
> that
> convergence might occur?

I am wondering how you expect us to guess at the answer? You are the  
one who know what "f" is and you are the one who has the option of  
increasing maxit. If the question is "how" to increase maxit, then the  
answer is perhaps as easy as:

?optim

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list