Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

How to continue a loop when NA/NaN/Inf error occurs in depmixS4 HMM fitting?

$
0
0

code:

for(j in 1:100){......     
for(k in 1:20) {
        fit.mod = fit(mod)
        if(AIC(fit.mod) < best) { best_model = fit.mod 
        best = AIC(fit.mod)
        } 
      fit.mod <- best_model
........}

when the error

Error in fb(init = init, A = trDens, B = dens, ntimes = ntimes(object),  : 
  NA/NaN/Inf in foreign function call (arg 10)

occurs, the loop automatically stops. I tried

if(is.na(fit.mod)){next}

and

if(!identical(fit.mod@message,c("Log likelihood converged to within tol. (relative change)"))){next}

But the loop still stops. Is there a method where I can ignore this error and continue the loop? Thanks in advance!


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>