[R] warning inside loop

Rense rense.nieuwenhuis at gmail.com
Tue Jan 12 00:06:51 CET 2010


Hi,

I'm running some data simulations using (mixed effects)* regression models
that show difficulty to converge. Therefore, I seek a way of capturing
warnings (of false convergence) inside a loop.

Inside that loop, I modify data and estimate a model. I do so many times
with slightly different modifications of the data. Next, I extract some of
the model parameters and store these in a matrix. However, as some of the
models do not converge well, some of the stored parameters are extracted
from the ill-converged models. Therefore, I seek a way of automatically
detecting whether the estimation procedure has resulted in a warning, so I
can distinguish between the well- and ill-converged models.

I have been trying to use functions as warnings(), as well as using the
object last.warning, but unfortunately to no avail.

Although I cannot provide a reproducible example, I schematically represent
the procedure I seek to use below:


for (i in 1:10)
{
<<modify data>>
<<estimate model>>

<<<evaluate whether estimation produced warning>>>

<<extract model parameters, and store whether warning occured>>
}

I hope any one can give some guidelines on how to deal with warnings inside
a loop.

With Kind regards,

Rense





*Although I use the lme4 package for that actual analysis, I sent my
question to this mailinglist (instead of the R mixed list) because I believe
this is a general issue, rather than one associated exclusively with mixed
models.
-- 
View this message in context: http://n4.nabble.com/warning-inside-loop-tp1011667p1011667.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list