[R] princomp with not non-negative definite correlation

John Maindonald john.maindonald at anu.edu.au
Wed Apr 16 02:52:29 CEST 2003

On Tuesday, April 15, 2003, at 08:14  PM,  tlumley at u.washington.edu 

> On Thu, 10 Apr 2003 tvr at stanford.edu wrote:
>> $ R --version
>> R 1.6.1 (2002-11-01).
>> So I would like to perform principal components analysis on a 16X16
>> correlation matrix, [princomp(cov.mat=x) where x is correlation 
>> matrix],
>> the problem is princomp complains that it is not non-negative 
>> definite.
>> I called eigen() on the correlation matrix and found that one of the
>> eigenvectors is close to zero & negative (-0.001832311). Is there any
>> way to work around this problem. A constraint: I only have the
>> correlation matrix, not the data that produced it.
> If you are confident the problem is due to rounding (or perhaps to 
> small
> amounts of missing data) you could set the smallest eigenvalue to zero.
> However, in revising an introductory biostatistics text recently I have
> found two correlation matrices with negative eigenvalues, both of which
> were actually data entry errors.

Of course, if the covariance matrix has been created using cov() with
use="pairwise.complete.obs", or there has been the equivalent of this
in another program, then it is perfectly possible to have a covariance
matrix with negative eigenvalues.

Inspection of the eigenvector that corresponds to the negative 
will in any case identify the (near?) dependency that is responsible.
The same information can be obtained directly using alias(lm(y~X))
where X is the matrix from which the covariance matrix was formed and
the values in y are immaterial, providing only none are missing & it is
the right length.  But, if there are missing values & you had used cov()
with the pairwise setting, you might be unlucky and find that  omission 
rows that have any missing values gives an X which appears to be
positive definite!

John Maindonald             email: john.maindonald at anu.edu.au
phone : +61 2 (6125)3473    fax  : +61 2(6125)5549
Centre for Bioinformation Science, Room 1194,
John Dedman Mathematical Sciences Building (Building 27)
Australian National University, Canberra ACT 0200.

More information about the R-help mailing list