Skip to content
Prev 248827 / 398503 Next

Positive Definite Matrix

I think the bottom line can be summarized as follows:


             1.  Give up on Cholesky factors unless you have a matrix 
you know must be symmetric and strictly positive definite.  (I seem to 
recall having had problems with chol even with matrices that were 
theoretically positive or nonnegative definite but were not because of 
round off.  However, I can't produce an example right now, so I'm not 
sure of that.)


             2.  If you must test whether a matrix is summetric, try 
all.equal(A, t(A)).  From the discussion, I had the impression that this 
might not always do what you want, but it should be better than 
all(A==t(A)).  It is better still to decide from theory whether the 
matrix should be symmetric.


             3.  Work with the Ae = eigen(A, symmetric=TRUE) or 
eigen((A+t(A))/2, symmetric=TRUE).  From here, Ae$values <- 
pmax(Ae$values, 0) ensures that A will be positive semidefinite (aka 
nonnegative definite).  If it must be positive definite, use Ae$values 
<- pmax(Ae$values, eps), with eps>0 chosen to make it as positive 
definite as you want.


             4.  To the maximum extent feasible, work with Ae, not A.  
Prof. Ripley noted, "You can then work with [this] factorization to 
ensure that (for example) variances are always non-negative because they 
are always computed as sums of squares.  This sort of thing is done in 
many of the multivariate analysis calculations in R (e.g. cmdscale) and 
in well-designed packages."


       Hope this helps.
       Spencer
On 1/30/2011 3:02 AM, Alex Smith wrote: