[R] Catch errors

Gang Chen gangchen at mail.nih.gov
Mon Aug 6 19:31:05 CEST 2007


I run a linear mixed-effects model in a loop

for (i in 1:N) {
    fit.lme <- lme(Y ~ X1*X2, random = ~1|subj, Model[i]);
}

As the data in some iterations are all (or most) 0's, leading to the  
following error message from lme:

Error in chol((value + t(value))/2) : the leading minor of order 1 is  
not positive definite

First the above error message stops the looping and does not allow me  
to continue the computation. So what is a good way to catch the error  
without spilling on the screen so that I can keep the looping and at  
the meantime stuff the corresponding output with some artificial  
value such as 0?

Thanks,
Gang



More information about the R-help mailing list