[R] error with princomp

Faheem Mitha faheem at email.unc.edu
Sun May 21 19:14:33 CEST 2000


Dear R people,

I have been doing some more sherlocking of a rather primitive sort. Thanks
very much for hints supplied by Peter Dalgaard and Bill Venables. I found
debug(princomp) would just exit with the same error. So, since the
calculations are really quite simple, I decided to follow them along,
creating the objects as needed. This approach was successful in detecting
the source of the prolem. The first column of my data set, corresponding
to the first variable, was all ones. This reasonably enough gave a lot of
zero covariances, and hence NaN's are generated down the line when
calculating the correlation matrix, hence throwing R into a tizzy. This
seems reasonable enough. I don't know enough about principal components
analysis to know whether R should be expected to do anything further with
a correlation matrix with missing values, but I doubt it. (Yes, the
correlation matrix seems to be the problem). I wonder how Splus coped with
it. I may take a look later if I have the energy.

I deleted this column and then ran into a further problem. When I tried to
do princomp(prin.df, cor = T) again I got

Error in princomp(prin.df, cor = T) : covariance matrix is not
non-negative definite.

I took a look at the covariance matrix and indeed some of the eigenvalues
were negative. However, they were very small negative numbers, ie

[86] -1.861163e-18 -3.507169e-18 -1.400653e-17 -4.185918e-17 -5.495597e-17
[91] -8.742655e-17 -1.227594e-16 -1.515011e-16 -2.975572e-16 -3.650603e-16
[96] -5.166079e-16 -1.719909e-15

Now, I am no expert on this stuff, but I think the covariance matrix
estimator is simply calculating the covariance matrix of the sample
distribution, so should be guaranteed to give a non-negative definite
matrix. So, I am inclined to think that this is probably a rounding error
and not my fault. What should be done about it? No, please don't tell me
to rewrite the code. I don't know enough.
                                                 Faheem.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list