[R] PC rotation question
Sasha Pustota
popgen at gmail.com
Fri May 26 21:21:06 CEST 2006
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
More information about the R-help
mailing list