Re: [Rd] Catching errors from solve() with near-singular matrices

2012-12-12 Thread David Sterratt
Dear all, many thanks to Jon & Ravi for their help on this, and apologies if r-help would have been a more appropriate forum. On Tue, 2012-12-11 at 15:43 +, Jon Clayden wrote: > Strategy 1: Some code like this: >if (det(X) < epsilon) { > warning("Near singular

Re: [Rd] Catching errors from solve() with near-singular matrices

2012-12-12 Thread Ravi Varadhan
I am not sure that this query is appropriate for r-devel, it seems to be more appropriate for r-help. In any case, you might want to try MASS::ginv instead of solve(), if you expect ill-conditioning. Here is one possible solution: f <- function(X) { invX <- tryCatch(ginv(X,

Re: [Rd] Catching errors from solve() with near-singular matrices

2012-12-11 Thread Jon Clayden
Dear David, I can think of two strategies for dealing with this problem: > > Strategy 1: Some code like this: >if (det(X) < epsilon) { > warning("Near singular matrix") > return(NULL) >} >return(solve(X)) This solution is probably the easiest one to take, but to match sol