[R] prcomp function
Claudia Beleites
cbeleites at units.it
Wed Nov 10 15:07:35 CET 2010
I think PCA decomposes matrix A according to A'A, not to COV (A).
But if A is centered then A'A = (n + 1) COV (A).
So for non-centered A, you want to look at A'A instead:
> crossprod(A) %*% evec[,1] / (nrow (A) - 1) - eval [1] * evec [,1]
[,1]
[1,] 0.000e+00
[2,] 0.000e+00
[3,] 1.066e-14
If I'm telling crap, someone please correct me!
Hope that helps,
Claudia
On 11/10/2010 02:41 PM, kicker wrote:
>
> Hello,
>
> I have a short question about the prcomp function. First I cite the
> associated help page (help(prcomp)):
>
> "Value:
> ...
> SDEV the standard deviations of the principal components (i.e., the square
> roots of the eigenvalues of the covariance/correlation matrix, though the
> calculation is actually done with the singular values of the data matrix).
> ROTATION the matrix of variable loadings (i.e., a matrix whose columns
> contain the eigenvectors). The function princomp returns this in the element
> loadings.
> ..."
>
> Now please take a look at the following easy example:
>
> first I define a matrix A
>> A<-matrix(c(0,1,4,1,0,3,4,3,0),3,3)
> then I apply PCA on A
>> trans<-prcomp(A,retx=T,center=F,scale.=F,tol=NULL)
>
>> eval<-trans$sdev*trans$sdev #eval is the vector of the eigenvalues of
> cov(A) (according to the cited help text above)
>> evec<-trans$rotation #evec is the matrix with the eigenvectors of cov(A) as
> columns (according to the cited help text above)
>
> now the eigenvalue equation should be valid, i.e. it should hold
> cov(A)%*%ev[,1]=ew[1]*ev[,1]. But it doesn´t, my result:
> cov(A)%*%ev[,1]= t(-0.8244927, -0.8325664,0.8244927)
> ew[1]*ev[,1]=t(-8.695427,-7.129314,-10.194816)
>
> So my question is : why does the eigenvalue equation not hold ?
>
> The eigenvalue equation holds when I set center=T in the options of the
> prcomp function. But as far as I know and as I understand the help text it
> should have no influence on the eigenvalue equation whether the data are
> centered or not. I know about the advantages of centered date but I want to
> understand how the prcomp function works in the case of uncentered data.
>
> Thank you very much for your efforts.
>
--
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste
phone: +39 0 40 5 58-37 68
email: cbeleites at units.it
More information about the R-help
mailing list