Here is a function that I use for symmetric matrices:

make.positive.definite <-
function(x, tol=1e-6) {
   eig <- eigen(x, symmetric=TRUE)
   rtol <- tol * eig$values[1]
   if(min(eig$values) < rtol) {
       vals <- eig$values
       vals[vals < rtol} <- rtol
       srev <- eig$vectors %*% (vals * t(eig$vectors))
       dimnames(srev) <- dimnames(x)
       return(srev)
   } else {
       return(x)
   }
}


Patrick Burns


Burns Statistics
[EMAIL PROTECTED]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")


[EMAIL PROTECTED] wrote:


Dear All,

I was wondering whether any one knows of a matrix bending function in R that can turn non-positive definite matrices into the nearest positive definite matrix. I was hoping there would be something akin to John Henshall's flbend program (http://agbu.une.edu.au/~kmeyer/pdmatrix.html), which allows the standard errors of the estimated matrix elements to be considered in the bending process.

Thanks,

Jarrod.

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help



______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to