[R-sig-ME] How to capture the warning message when a lmer model fails to converge or have singular convergence

Ben Bolker bbolker at gmail.com
Sun May 6 02:39:21 CEST 2012


Xiao He <praguewatermelon at ...> writes:

> 
> Hi dear R users,
> 
> I am trying to write a script to compare models with the same fixed effects
> but different random effects e.g.,
> 
   [snip]
> 
> The idea is that I can input a full model (e.g., model1), and the script
> will compare it with model2, if the p-value is above a user-defined level
> (e.g., 0.1), model2 will be selected. Then the script will compare model2
> with model3. etc.
> 
> Since sometimes certain models fail to converge or have singular
> convergence, I would like the script to be able to note that and decide
> what to do next accordingly.
> 
> For example, in the case of failure to converge (e.g., if model1 fails to
> converge), I would like the script to choose a simpler model (e.g., Model2)
> and compare it with an even simpler model (e.g., model3).
> 
> I am not sure if this is doable within my capacity. So far, I've been able
> to write a script to do a series of comparisons, but problems arise when
> there are errors such as failure to converge.
> 

  This is a bit of a pain, but you can either (more simply) use
options(warning=2) to promote warnings to errors and then catch
the errors with try(), or you can do a more thorough/rigorous
version by using withCallingHandlers() to intercept the warnings.
This is (to my mind) a bit tricky but you can see an example in
http://glmm.wdfiles.com/local--files/examples/Zhang_simfuns.R



More information about the R-sig-mixed-models mailing list