[R] positive semi-definite matrix

Duncan Murdoch murdoch at stats.uwo.ca
Fri Jul 21 15:44:42 CEST 2006


On 7/21/2006 8:59 AM, roger bos wrote:
> I have a covariance matrix that is not positive semi-definite matrix and I
> need it to be via some sort of adjustment.  Is there any R routine or
> package to help me do this?

I think you need to be more specific about what have and what you want, 
but if the matrix is symmetric and nearly positive semi-definite (but 
not exactly because of rounding error), you might try something like

fixit <- function(A) {
   eig <- eigen(A, symmetric = TRUE)
   eig$values <- pmax(0, eig$values)
   return(eig$vectors %*% diag(eig$values) %*% t(eig$vectors))
}

Rounding error means this is not guaranteed to be positive 
semi-definite, but it will be very close.

Duncan Murdoch



More information about the R-help mailing list