tvr@stanford.edu
2003-Apr-11 04:09 UTC
[R] princomp with not non-negative definite correlation matrix
$ 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. I believe I could replicate most of the functionality of princomp step-by-step (loadings, scores, etc.) and track the effect of the negative eigenvector on the rest of the analysis, but I'd rather not do that with every covariance/correlation matrix that might have a few eigenvectors that are negative but close to zero. (I've attached the matrix if anyone wants to replicate the error) -------------- next part -------------- 1.00 0.99 0.36 0.99 0.91 0.25 0.31 0.44 0.22 0.45 0.66 0.16 0.39 0.34 0.55 0.02 0.99 1.00 0.34 0.99 0.92 0.25 0.31 0.44 0.22 0.45 0.66 0.16 0.39 0.33 0.55 0.01 0.36 0.34 1.00 0.32 0.28 0.21 0.08 0.33 0.23 0.34 0.29 0.08 0.32 0.18 0.36 0.04 0.99 0.99 0.32 1.00 0.89 0.25 0.33 0.44 0.22 0.45 0.67 0.13 0.39 0.36 0.54 0.01 0.91 0.92 0.28 0.89 1.00 0.24 0.28 0.38 0.19 0.42 0.49 0.17 0.32 0.27 0.54 0.01 0.25 0.25 0.21 0.25 0.24 1.00 0.48 0.69 0.62 0.69 0.29 0.32 0.67 0.46 0.65 0.18 0.31 0.31 0.08 0.33 0.28 0.48 1.00 0.35 0.28 0.35 0.26 0.15 0.33 0.26 0.33 0.01 0.44 0.44 0.33 0.44 0.38 0.69 0.35 1.00 0.91 0.95 0.54 0.43 0.99 0.65 0.77 0.15 0.22 0.22 0.23 0.22 0.19 0.62 0.28 0.91 1.00 0.77 0.31 0.34 0.92 0.59 0.54 0.07 0.45 0.45 0.34 0.45 0.42 0.69 0.35 0.95 0.77 1.00 0.51 0.47 0.93 0.57 0.84 0.19 0.66 0.66 0.29 0.67 0.49 0.29 0.26 0.54 0.31 0.51 1.00 0.20 0.50 0.49 0.53 0.14 0.16 0.16 0.08 0.13 0.17 0.32 0.15 0.43 0.34 0.47 0.20 1.00 0.35 0.30 0.34 0.16 0.39 0.39 0.32 0.39 0.32 0.67 0.33 0.99 0.92 0.93 0.50 0.35 1.00 0.57 0.71 0.13 0.34 0.33 0.18 0.36 0.27 0.46 0.26 0.65 0.59 0.57 0.49 0.30 0.57 1.00 0.49 0.16 0.55 0.55 0.36 0.54 0.54 0.65 0.33 0.77 0.54 0.84 0.53 0.34 0.71 0.49 1.00 0.20 0.02 0.01 0.04 0.01 0.01 0.18 0.01 0.15 0.07 0.19 0.14 0.16 0.13 0.16 0.20 1.00
Prof Brian Ripley
2003-Apr-14 08:27 UTC
[R] princomp with not non-negative definite correlation matrix
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. > > I believe I could replicate most of the functionality of princomp > step-by-step (loadings, scores, etc.) and track the effect of the > negative eigenvector on the rest of the analysis, but I'd rather not do > that with every covariance/correlation matrix that might have a few > eigenvectors that are negative but close to zero.No correlation/covariance matrix ever has negative eigenvectors, so princomp is correctly telling you that you have a problem. I have no idea what your matrix is, but it is not a correlation matrix. Possibly it has been written out and rounded? In that case try setting the negative eigenvalues to zero. But I would want to be sure that there was not some more serious error in the correlation matrix. -- 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
Thomas Lumley
2003-Apr-14 13:50 UTC
[R] princomp with not non-negative definite correlation matrix
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. -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle