[R] How to flag those iterations which yield a warning?

David Winsemius dwinsemius at comcast.net
Fri Feb 18 17:47:09 CET 2011


On Feb 18, 2011, at 11:35 AM, Ravi Varadhan wrote:

> May be I could do:
>
> for (i in 1:nsim) {
>
> last.warning <- NULL
>
> # do model fitting
>
> if(!is.null(last.warning)) # discard simulation result

You can raise warnings to behave as errors with options:

options(warn=2)

And you can define where R goes on error with

options(error=  ... some function

?options

?utils::recover

>
> I think this might work.  Any other ideas?
>
> Ravi.
>
> ____________________________________________________________________
>
> Ravi Varadhan, Ph.D.
>> Hi,
>>
>> I am running a simulation study with the survival::coxph.  Some of
>> the simulations result in problematic fits due to flat partial
>> likelihood. So, you get the warning message:
>>
>> Warning message:
>> In fitter(X, Y, strats, offset, init, control, weights = weights,
>> ... :
>>   Loglik converged before variable  2 ; beta may be infinite.
>>
>> How can I keep track of the simulations which yield any kind of
>> warning message, so that I can appropriately handle them in the
>> post-processing of simulation results?
>>
>> I know that `try' can be used to capture errors, but I would like to
>> capture and detect warnings.
>>
>> Any pointers would be appreciated.
>>
>> Thanks,
>> Ravi.
>> ____________________________________________________________________
>>
>> Ravi Varadhan, Ph.D.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list