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

2 replies [Last post]
Jean's picture
Offline
Joined: 11/10/2009

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

mhunter's picture
Offline
Joined: 07/31/2009
That should work

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)

Jean's picture
Offline
Joined: 11/10/2009
Hey Mike, that's super

Hey Mike, that's super helpful! Thank you~