[Rd] prcomp scale error (PR#6433)

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Jan 15 16:25:37 MET 2004


ryszard.czerminski at pharma.novartis.com writes:

> prcomp(..., scale = TRUE) does not work correctly:
> 
> $ uname -a
> Linux 2.4.20-28.9bigmem #1 SMP Thu Dec 18 13:27:33 EST 2003 i686 i686 i386
> GNU/Linux
> $ gcc --version
> gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
> 
> > a <- matrix(rnorm(6), nrow = 3)
> > sum((scale(a %*% svd(cov(a))$u, scale = F)[,1] - (prcomp(a, scale =
> F)$x)[,1])^2)
> [1] 2.465190e-31
> > sum((scale(a %*% svd(cov(a))$u, scale = T)[,1] - (prcomp(a, scale =
> T)$x)[,1])^2)
> [1] 0.5493767

Eh? I may be not quite up to speed on my PCA theory, but I fail to see
why you should expect to have any relation between prcomp(..., scale=T)
and an SVD of the covariance matrix. What you do have is

> sum(((scale(a, scale=T) %*% svd(cor(a))$u)[,1] - (prcomp(a, scale =
+ T)$x)[,1])^2)
[1] 6.498858e-30


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907



More information about the R-devel mailing list