----- Forwarded message from Marko Djurakic -----
Date: Fri, 6 Jun 2014 09:25:03 -0400
From: Marko Djurakic
Reply-To: Marko Djurakic
Subject: Re: Comparing svd() and prcomp() output from R
To: [email protected]
On 6.6.2014 11:09, [email protected] wrote:
Hi folks,
This is really a R question, but perhaps someone can help me.
When I run svd() and prcomp() functions on my procrustes aligned coordinates, I
end up with an interesting situation, where the 1st component from the prcomp()
is identical to the 2nd component from svd() and it keeps going with this shift.
The first component from SVD has a large variance attached to it. If you remove
that and recalculate the percentages, they are identical to the variances
explained by prcomp.
Any ideas what's happening?
Thanks,
M
Hi,
I am not able to answer why did you obtain such shift between svd() and
prcomp(), but below is a way how you can obtain identical results using those
functions.
Probably you provided an incorrect input for svd(). Both prcomp() and svd() use
the singular value decomposition to find eigenvectors and eigenvalues. However,
functions differ regarding required inputs. prcomp() works on a matrix of
Procrustes aligned coordinates (e.g rows are individuals and columns are
x,y,(z) variables). If you want to obtain results using svd() you must provide
covariance matrix of the CENTERED data rather than matrix of Procrustes aligned
coordinates. If you do this accordingly, svd() will return eigenvalues and
eigenvectors, and individual scores can be computed by multiplying eigenvectors
with original data (matrix of the CENTERED data).
If you are interested here is David Polly's great tutorial that might help:
http://www.indiana.edu/~g562/PBDB2013/Day%203B%20-%20PCA%20and%20morphospace.pdf
Here I summarized svd() and prcomp() comparison:
## Load package, data, perform GPA, format Procrustes coordinates into two
dimensional array (e.g rows are individuals and columns are x,y variables)
library (geomorph)
data (plethodon)
coords