[R] Parameters setting in functions optimization

Diane Bailleul diane.bailleul at u-psud.fr
Tue Nov 29 19:15:43 CET 2011


Good afternoon everybody,
I'm quite new in functions optimization on R and, whereas I've read 
lot's of function descriptions, I'm not sure of the correct settings for 
function like "optimx" and "nlminb".
I'd like to minimize my parameters and the loglikelihood result of the 
function.
My parameters are a mean distance of dispersion and a proportion of 
individuals not assigned, coming from very far away.
The function LikeGi reads external tables and it's working as I want 
(I've got a similar model on Mathematica).

My "final" function is LogLiketot :
LogLiketot<- function(dist,ms)
{
res <- NULL
for(i in 1:nrow(pop5)){
     for(l in 1:nrow(freqvar)){
res <- c(res, pop5[i,l]*log(LikeGi(l,i,dist,ms)))
     }
         }
return(-sum(res))
             }

dist is the mean dispersal distance (0, lots of meters) and ms the 
proportion of individuals (0-1).
Of course, I want them to be as low as possible.

I'd tried to enter the initials parameters as indicated in the tutorials :
optim(c(40,0.5), fn=LogLiketot)
 >Error in 1 - ms : 'ms' is missing
But ms is 0.5 ...

So I've tried this form :
optimx(c(30,50),ms=c(0.4,0.5), fn=LogLiketot)
with different values for the two parameters :
                     par  fvalues      method fns grs itns conv KKT1 
KKT2 xtimes
 >2    19.27583, 25.37964 2249.698        BFGS  12   8 NULL    0 TRUE 
TRUE   57.5
 >1 29.6787861, 0.1580298 2248.972 Nelder-Mead  51  NA NULL    0 TRUE 
TRUE   66.3

The first line is not possible but as I've not constrained the 
optimization ... but the second line would be a very good result !

Then, searching for another similar cases, I've tried to change my 
function form:

LogLiketot<- function(par)
{
res <- NULL
for(i in 1:nrow(pop5)){
     for(l in 1:nrow(freqvar)){
res <- c(res, pop5[i,l]*log(LikeGi(l,i,par[1],par[2])))
     }
         }
return(-sum(res))
             }

where dist=par[1] and ms=par[2]

And I've got :
optimx(c(40,0.5), fn=LogLiketot)
                     par  fvalues      method fns grs itns conv KKT1 
KKT2 xtimes
 >2 39.9969607, 0.9777634 1064.083        BFGS  29  10 NULL    0 TRUE   
NA  92.03
 >1 39.7372199, 0.9778101 1064.083 Nelder-Mead  53  NA NULL    0 TRUE   
NA  70.83
And I've got now a warning message :
 >In log(LikeGi(l, i, par[1], par[2])) : NaNs produced
(which are very bad results in that case)


Anyone with previous experiences in optimization of several parameters 
could indicate me the right way to enter the initial parameters in this 
kind of functions ?

Thanks a lot for helping me !

Diane

-- 
Diane Bailleul
Doctorante
Université Paris-Sud 11 - Faculté des Sciences d'Orsay
Unité Ecologie, Systématique et Evolution
Département Biodiversité, Systématique et Evolution
UMR 8079 - UPS CNRS AgroParisTech
Porte 320, premier étage, Bâtiment 360
91405 ORSAY CEDEX FRANCE
(0033) 01.69.15.56.64



More information about the R-help mailing list