using mxRun (unsafe=TRUE) to skip error and continue loop?

Posted on
No user picture. Jean Joined: 11/10/2009
Forums
Hi,

I'm running a simulation in which a model will be fit to the simulated data 1000 times by running a loop.

However, some simulated data will make the model return error, like below:
Error: The job for model 'myModel' exited abnormally with the error message: Objective function returned a value of NaN at iteration 52.23.

May I use the option unsafe=TRUE in mxRun to skip error and continue the loop?

Thank you.

Best,
Jean

Replied on Thu, 03/07/2013 - 17:34
Picture of user. mhunter Joined: 07/31/2009

Hey Jean!

That should work. The unsafe argument to mxRun just omits the stop command when an error is encountered. Instead, the error is treated like a warning. It's probably a good idea to keep some kind of track of the models that fail. This can be done by saving and/or storing the output status.

yourModel@output$status

This keeps the status code(s) and error/warning message(s). It is a list so you could probably turn it into a data.frame and keep records for all 1000 model runs.

data.frame(yourModel@output$status)