0

i'm using R, the "optim" code to obtain maxims of a function. I'm performing the optimization 100 times with equally number random samples but in cases there's one sample for you can't obtain the result and i get this error code:

Error en optim(theta, objective, yt = rbind(yt), hessian = TRUE) :
non-finite finite-difference value [3]

since is an iterative process when this happens the code stop and don't save the previous results

is there any way to indicate that if i get this error message the routine continues anyway?

i was thinking using a "for" line, let's say

if(length(fit)!=6){fit <-c(0,0,0)}

or

if(fit=="NA"){fit$par <-c(0,0,0)}

here fit is the name i gave to the optim line.

So that way instead of getting the error i would assign a vector of zeros and the routine can goes on but it didn't work. Any ideas or comments?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190

0 Answers0