Dae-Jin Lee
2007-Jul-30 16:59 UTC
[R] stop criteria when "L-BFGS-B needs finite values of 'fn' " in optim
Hi all! I'm running some simulations and I need to estimate some paramaters with optim( ), in some cases optim stops with the next message: "L-BFGS-B needs finite values of 'fn' " I would like to know how to include and "if" condition when this happen, could it be something like: myfun <- optim(....) # run my function ???? if(myfun == ERROR) ..... # when the error message is "L-BFGS-B needs finite values of 'fn' ???? I've succesfully achieved when, for example convergence is not reached, if(myfun$convergence != 0) but I don't know how to do it in the other case Any help?? Thanks in advance, Dae-Jin -- __________________________________ Dae-Jin Lee Despacho: 7.3.J04 Tlfno: 91 624 9175 Fax: 91 624 9430 Departamento de EstadÃstica Av. Universidad 30, Ed. Juan Benet 28911 Leganés (Madrid) Universidad Carlos III de Madrid e-mail: dae-jin.lee@uc3m.es web: http://www.est.uc3m.es/daejin __________________________________ [[alternative HTML version deleted]]
Ben Bolker
2007-Jul-31 15:21 UTC
[R] stop criteria when "L-BFGS-B needs finite values of 'fn' " in optim
Dae-Jin Lee <dae-jin.lee <at> uc3m.es> writes:> > > I would like to know how to include and "if" condition when this happen, > could it be something like: > > myfun <- optim(....) # run my function > > ???? > if(myfun == ERROR) ..... # when the error message is "L-BFGS-B needs > finite values of 'fn' > ???? >See ?try : e.g. myfun <- try(optim(...)) if (class(myfun)=="try-error") { ... whatever ... } else { ... success ... } or tryCatch this is FAQ 7.32 ... cheers Ben Bolker