Re: [R] PC rotation question

From: Sasha Pustota <popgen_at_gmail.com>
Date: Sat 27 May 2006 - 05:21:06 EST

I wrote:
> On p. 48 of "Statistics Complements" to the 3rd MASS edition,
> http://www.stats.ox.ac.uk/pub/MASS3/VR3stat.pdf
> I read that the orthogonal rotations of Z Lambda^-1 remain
> uncorrelated, where Z is the PC and Lambda is the diag matrix of
> singular values. However, the example below that text is
> > A <- loadings(ir.pca) %*% diag(ir.pca$sdev)
> If ir.pca$sdev are the singular values, should that be diag(1 /
> ir.pca$sdev), or is it some discrepancy between S+ and R that I'm
> missing?

To dwell some more on this and in hopes to get replies I did a small experimantation (below) that makes me to suspect that the correct syntax
is A <- loadings(ir.pca) %*% diag(1/ir.pca$sdev). Any comments?

library(MASS)

a <- 1; b <- 0.2; c <- -.3; d <- .7
x <- scale(mvrnorm(n=1000,c(0,0,0),matrix(c(a,b,c, b,a,d, c,d,a),3,3)))
e <- eigen(cov(x))

cat("expect identity corr for orthogonal rotations:\n") zs <- e$vectors %*% diag(1/sqrt(e$values)) pdx <- x %*% varimax(zs, normalize = FALSE)$loadings print.table(cor(pdx), digits=2)

cat("expect zero: ", prcomp(x)$sdev - sqrt(e$values), "\n")

cat("Now zero corr between projections is not preserved:\n") zs <- e$vectors %*% diag(sqrt(e$values)) pdx <- x %*% varimax(zs, normalize = FALSE)$loadings print.table(cor(pdx), digits=2)

Output:
expect identity corr for orthogonal rotations:

     [,1] [,2] [,3]

[1,]  1.0e+00 -3.0e-16 -4.5e-16
[2,] -3.0e-16  1.0e+00  2.3e-16
[3,] -4.5e-16  2.3e-16  1.0e+00

expect zero: 4.440892e-16 2.220446e-16 2.775558e-16 Now zero corr between projections is not preserved:

     [,1] [,2] [,3]

[1,]  1.00 -0.35 -0.88
[2,] -0.35  1.00 -0.11
[3,] -0.88 -0.11  1.00

______________________________________________
R-help@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 Received on Sat May 27 05:27:46 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 27 May 2006 - 06:10:29 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.