[R] A simple question about PRINCOMP

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri May 11 10:48:06 CEST 2007


Yes, rounding error does happen in real-life computation.  It would be 
extraordinary to compile the correlation of real data and get exactly 0: 
this would require that the data could be represented exactly, for 
example.

You might find ?zapsmall helpful.

On Thu, 10 May 2007, Takatsugu Kobayashi wrote:

> Hi,
>
> I just wonder if this is a rounding error by the princomp command in R.
>
> Although this does not make much sense, using a hypothetical dataset, a,
>
> a<-matrix(runif(1000),100,10)
>
> I did PCA with the princomp, and compared it with the results estimated
> with the eigen and the prcomp commands. And I found some differences in
> the results: opposite signs in the loadings; slight differences in
> variances (lambdas), etc. Since the components are orthogonal to each
> other, correlation coefficients between the PC scores should be zero.
> But when I type
>
> test2<-princomp(a)
> cor(test2$scores)
>
> I obtained the following cor matrix:
>
>               Comp.1        Comp.2        Comp.3        Comp.4
> Comp.5        Comp.6        Comp.7        Comp.8
> Comp.1   1.000000e+00 -5.819229e-15  1.952317e-16 -1.631710e-16
> 5.489998e-17  5.624600e-17  1.582736e-16 -3.048016e-17
> Comp.2  -5.819229e-15  1.000000e+00 -1.942578e-16  7.219253e-17
> -7.107726e-17  3.492899e-17 -6.670908e-17  1.527489e-16
> Comp.3   1.952317e-16 -1.942578e-16  1.000000e+00  4.922440e-16
> 4.105868e-17  6.342858e-16  2.930614e-16  6.296834e-17
> Comp.4  -1.631710e-16  7.219253e-17  4.922440e-16  1.000000e+00
> 1.308663e-17 -4.556627e-16  2.927150e-16 -1.001956e-17
> Comp.5   5.489998e-17 -7.107726e-17  4.105868e-17  1.308663e-17
> 1.000000e+00  1.169042e-16  1.401771e-16  4.732978e-17
> Comp.6   5.624600e-17  3.492899e-17  6.342858e-16 -4.556627e-16
> 1.169042e-16  1.000000e+00 -4.193547e-16  5.742884e-17
> Comp.7   1.582736e-16 -6.670908e-17  2.930614e-16  2.927150e-16
> 1.401771e-16 -4.193547e-16  1.000000e+00  3.179465e-16
> Comp.8  -3.048016e-17  1.527489e-16  6.296834e-17 -1.001956e-17
> 4.732978e-17  5.742884e-17  3.179465e-16  1.000000e+00
> Comp.9  -4.092284e-17  1.977862e-16 -1.140905e-16 -2.566213e-16
> 2.647648e-17  8.279450e-17  1.603418e-16 -4.015096e-17
> Comp.10 -1.017709e-17 -2.673821e-17 -5.851822e-17  4.417901e-17
> 2.760632e-17  1.247873e-17 -1.622996e-17  4.921851e-17
>               Comp.9       Comp.10
> Comp.1  -4.092284e-17 -1.017709e-17
> Comp.2   1.977862e-16 -2.673821e-17
> Comp.3  -1.140905e-16 -5.851822e-17
> Comp.4  -2.566213e-16  4.417901e-17
> Comp.5   2.647648e-17  2.760632e-17
> Comp.6   8.279450e-17  1.247873e-17
> Comp.7   1.603418e-16 -1.622996e-17
> Comp.8  -4.015096e-17  4.921851e-17
> Comp.9   1.000000e+00  2.843887e-16
> Comp.10  2.843887e-16  1.000000e+00
>
> Aren't all off-diagonal elements in this particular matrix zeros? I am
> sure that these off-diagonal values are substantially small and close to
> zero. But is this because of these commands' rounding error or that I
> did something wrong...?
>
> Thanks in advance.
>
> Taka
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
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



More information about the R-help mailing list