[R] a question on R optimization functions

Paul Gilbert pgilbert at bank-banque-canada.ca
Fri Mar 25 16:27:56 CET 2011


It seems more likely that the return value from your function is NA or NaN or Inf. This might then result in an NA parameter value being calculated for the next step. This is possible, for example,  because the line search extends outside the feasible region. You can re-write your function to check for that case and return a large negative value (or positive if minimizing), or stop() if that is more appropriate.

Paul

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Dajiang J. Liu
> Sent: March 25, 2011 3:59 AM
> To: r-help at r-project.org
> Subject: [R] a question on R optimization functions
> 
> Dear All,
> 
> I use nlminb or optim for maximizing likelihood functions. Sometimes,
> the parameter values happen to be NA, then the program will hang there
> and iterate forever without stopping. No error message will be
> produced. So I can not use error catch method such as "try". Are there
> any suggestions how I can circumvent this problem? Maybe I can time a
> function, and if the time exceeds a threshold, it will be stopped. I
> am not sure if this is feasible in R. As a note, I am running
> simulations with thousands of replicates, so there needs to be a
> systematic way of doing this. Are there any suggestions on how to do
> this? Thank you very much!
> 
> Regards,
> Dajiang
> 
> ______________________________________________
> R-help at 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.
====================================================================================

La version française suit le texte anglais.

------------------------------------------------------------------------------------

This email may contain privileged and/or confidential information, and the Bank of
Canada does not waive any related rights. Any distribution, use, or copying of this
email or the information it contains by other than the intended recipient is
unauthorized. If you received this email in error please delete it immediately from
your system and notify the sender promptly by email that you have done so. 

------------------------------------------------------------------------------------

Le présent courriel peut contenir de l'information privilégiée ou confidentielle.
La Banque du Canada ne renonce pas aux droits qui s'y rapportent. Toute diffusion,
utilisation ou copie de ce courriel ou des renseignements qu'il contient par une
personne autre que le ou les destinataires désignés est interdite. Si vous recevez
ce courriel par erreur, veuillez le supprimer immédiatement et envoyer sans délai à
l'expéditeur un message électronique pour l'aviser que vous avez éliminé de votre
ordinateur toute copie du courriel reçu.


More information about the R-help mailing list