Dear R-users, Is there a preferred method for testing whether a real symmetric matrix is positive definite? [modulo machine rounding errors.] The obvious way of computing eigenvalues via "E <- eigen(A, symmetric=T, only.values=T)$values" and returning the result of "!any(E <= 0)" seems less efficient than going through the LU decomposition invoked in "determinant.matrix(A)" and checking the sign and (log) modulus of the determinant. I suppose this has to do with the underlying C routines. Any thoughts or anecdotes? Many Thanks, Makram Talih -- Makram Talih, Ph.D. Assistant Professor Department of Mathematics and Statistics Hunter College of the City University of New York 695 Park Avenue, Room 905 HE New York, NY 10021 Website: http://stat.hunter.cuny.edu/talih E-mail: makram.talih at hunter.cuny.edu Tel: 212-772-5308 Fax: 212-772-4858
My preference is to test see if the smallest eigenvalue is less than something like sqrt(.Machine$double.eps) times the largest. This may be too conservative, but if the ratio of the smallest to the largest is less than some small number like that, the inverse of such a real symmetric matrix will have very large eigenvalue(s) in potentially unstable directions. R may have other functions beside eigen that will explicitly consider the symmetry of a matrix, but I'm not familiar with them. spencer graves Makram Talih wrote:> Dear R-users, > > Is there a preferred method for testing whether a real symmetric matrix is > positive definite? [modulo machine rounding errors.] > > The obvious way of computing eigenvalues via "E <- eigen(A, symmetric=T, > only.values=T)$values" and returning the result of "!any(E <= 0)" seems > less efficient than going through the LU decomposition invoked in > "determinant.matrix(A)" and checking the sign and (log) modulus of the > determinant. > > I suppose this has to do with the underlying C routines. Any thoughts or > anecdotes? > > Many Thanks, > > Makram Talih > > -- > Makram Talih, Ph.D. > Assistant Professor > Department of Mathematics and Statistics > Hunter College of the City University of New York > 695 Park Avenue, Room 905 HE > New York, NY 10021 > > Website: http://stat.hunter.cuny.edu/talih > E-mail: makram.talih at hunter.cuny.edu > Tel: 212-772-5308 > Fax: 212-772-4858 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA spencer.graves at pdf.com www.pdf.com <http://www.pdf.com> Tel: 408-938-4420 Fax: 408-280-7915
On Wed, 13 Jul 2005, Makram Talih wrote:> Dear R-users, > > Is there a preferred method for testing whether a real symmetric matrix is > positive definite? [modulo machine rounding errors.] > > The obvious way of computing eigenvalues via "E <- eigen(A, symmetric=T, > only.values=T)$values" and returning the result of "!any(E <= 0)" seems > less efficient than going through the LU decomposition invoked in > "determinant.matrix(A)" and checking the sign and (log) modulus of the > determinant. > > I suppose this has to do with the underlying C routines. Any thoughts or > anecdotes?It has to do with what exactly you want to test. Knowing the determinant does not tell you if the matrix is close to non-positive definite or not. For numerical work, a comparison of the smallest eigenvalue to the largest is usually the most useful indication of possible problems in computations. An alternative is to try a Choleski decomposition, which may be faster but is less informative. Given how fast eigenvalues can be computed by current algorithms (and note the comments in ?eigen) I would suggest not worrying about speed until you need to (probably never). -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595