[R] try to silence errors

MacQueen, Don macqueen1 at llnl.gov
Thu Dec 22 19:43:04 CET 2011


Something like the following may be what you are looking for.

try.out <- try(dmt(y[,j],new$mu[,,4],sigij,ceiling(new$nu[4])),silent=TRUE)

if (class(try.out) == 'try-error'} ) {
  out <- NaN
} else {  out <- try.out
}
-Don


-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 12/22/11 7:59 AM, "statfan" <irene_vrbik at hotmail.com> wrote:

>I am trying to use the dmt function in the package {mnormt}.  Throughout
>my
>algorithm, the covariance matrix is sometime calculated to be singular.
>When attempting to calculate the dmt function with a covariance that is
>not
>positive definite, I would like it to return Inf or NaN instead of an
>error
>message.
>
>I have been using the try function, however it is not yeilding the desired
>result. (I did not include the values since they are 17 dimensions, all
>you
>need to know is that sigij is singular)
>
>try(out <- dmt(y[,j],new$mu[,,4],sigij,ceiling(new$nu[4])),silent=TRUE)
>Error in chol.default(x, pivot = FALSE) :
>  the leading minor of order 16 is not positive definite
>
>I have similarly tried the trycatch function (see below for code) however
>I
>am using this within a function made my be  (which i call "ll") so I get
>errors like
> ll <- function(new,y){	
>.......
>out <- tryCatch(dmt(y[,j],new$mu[,,3],sigij,
> 	ceiling(new$nu[3])),error = function(e) -Inf)
>....
>}
>
>ll(new,y)
>Error in chol.default(x, pivot = FALSE) :
>  the leading minor of order 16 is not positive definite
>[1] -Inf
>
>If anyone could shed some light on this problem, it would be greatly
>appreciated.
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/try-to-silence-errors-tp4225754p4225754.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list