bwlewis/irlba

Why do i have different results for irlba$v and prcomp_irlba$rotation for the same matrix?

MrChenFeng opened this issue · 3 comments

set.seed(1)
x <- matrix(rnorm(200), nrow=20)
p1 <- prcomp_irlba(x, n=3)
p3 <- irlba(A=x, nv=3)
and i got p1$rotation :
image
p3$v:
image

If im not wrong ,maybe it should have X=UΔV‘ (SVD) and UΔ = XV(PCA)

since i even found that
image

Because they don't compute the same decomposition by default. It's equivalent to the difference between svd and prcomp. irlba computes a singular value decomposition. prcomp_irlba computes a principal component decomposition with centering.

Try, for instance,

set.seed(1)
x <- matrix(rnorm(200), nrow=20)
p1 <- prcomp_irlba(x, n=3)
p3 <- irlba(A=x, nv=3)
p2 <- irlba(x, nv=3, center=colMeans(x))

Now p2$v and p1$rotation agree up to sign.

Sorry I just forget this question cause I found the error myself later....But still great thanks!!!!