[R] prcomp function
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  * evec [,1]
If I'm telling crap, someone please correct me!
Hope that helps,
On 11/10/2010 02:41 PM, kicker wrote:
> I have a short question about the prcomp function. First I cite the
> associated help page (help(prcomp)):
> 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
> Now please take a look at the following easy example:
> first I define a matrix A
> then I apply PCA on A
>> 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*ev[,1]. But it doesn´t, my result:
> cov(A)%*%ev[,1]= t(-0.8244927, -0.8325664,0.8244927)
> 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.
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
phone: +39 0 40 5 58-37 68
email: cbeleites at units.it
More information about the R-help