Normalizing PCA from plotTangentSpace

190 views
Skip to first unread message

Nils V

unread,
Sep 7, 2017, 6:31:59 AM9/7/17
to geomorph R package
Hi,
I'm not the best at R so I'm having a bit of trouble.

Is there anyway to normalize the PCA results from plotTangentSpace? Similar to using prcomp(x, size=true). Or is it already normalized?

I'm trying to perform a procrustes (using vegan package), comparing two seperate PCA results from prcomp and from plotTangentSpace on the same objects, but due to differences in PCA scale it ends up coming warped (see attached).

Any help would be appreciated!

Cheers,
Nils
procrustes error.png

Mike Collyer

unread,
Sep 7, 2017, 6:48:10 AM9/7/17
to geomorph-...@googlegroups.com
Hi Nils,

Because you volunteered being “not the best at R”, I’ll try to provide some help for not just this function but any R function that does the same thing.  plotTangentSpace is a function that has “ellipsis” programming.  What this means in R is that arguments in one function can be passed onto another function the first function uses.  For plotTangentSpace, we use prcomp, so the ellipsis programming (denoted as “…" in the arguments) allows any argument one might use in prcomp to also be used in plotTangentSpace.  Whenever you see “…” in an argument for an R function, it means there are other functions that can be manipulated by the main function.

For plotTangentSpace, you mentioned “normalizing” the PCA results and used a size = T argument to indicate your intention.  I think you meant standardizing the variables (to make a correlation matrix instead of a covariance matrix), which is scale. = T in prcomp.  Thus, you can do

myPCA <- plotTangentSpace(myCoords, .scale = T)

to accomplish this.  Realize that the warpgrids will not make much sense, as we do not have a step for un-standardizing the data, but the PC scores that result should be what you seek.  If this is not what you intended, then whichever prcomp argument you would like to change can be changed also in plotTangentSpace.

Hope that helps!
Mike


--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.
To view this discussion on the web, visit https://groups.google.com/d/msgid/geomorph-r-package/d5a73d2b-9dab-4b8c-bedc-959a25314ffb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<procrustes error.png>

Antigoni Kaliontzopoulou

unread,
Sep 7, 2017, 6:48:31 AM9/7/17
to geomorph-...@googlegroups.com
Hi Nils,

not sure what you mean by "normalizing" PCA results, do you want to center and scale the data? prcomp does not have, as far as I recall a "size" argument as your code suggests...

Anyway, if what you want to do is center and scale, yes, you can pass these prcomp arguments directly to plotTangentSpace, as the function uses prcomp under the hood. Caution is needed if you want to visualize the results in terms of shape variation, though, as centering shape data substracts the mean shape configuration from your coordinates. This means that after applying such a centering, your data will "loose" their geometric properties, and deformation grids will look weird. For visualization, you would need to add back the consensus to your pca data.

Not sure this is what you meant, though.
All the best,
Antigoni


--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.
To post to this group, send email to geomorph-r-package@googlegroups.com.



--


Antigoni Kaliontzopoulou

Assistant Researcher
CIBIO/InBIO, Centro de Investigação em Biodiversidade e Recursos Genéticos
University of Porto
Campus Agrário de Vairão, 4485-661 Vairão
PORTUGAL

http://antigonik.wix.com/akaliontzopoulou
http://cibio.up.pt/people/details/akaliont
http://aphylogenetics.wix.com/phylogenetics

Nils V

unread,
Sep 7, 2017, 10:48:14 AM9/7/17
to geomorph R package
Hi Michael and Antigoni,

Thanks for the help, I think you both understood what I failed to explain properly. In my original message where I accidentally wrote "size = T", where Michael correctly picked up I meant "scale = T".
Glad to know it works the same as prcomp. It seems to work, although the visualization leaves much to be desired

I was trying to compare the difference in variation produced by two different morphometric methods using procrustes. However, if standardizing them warps the visualization then it's changing the results, so it's probably not the best way to do it then.   Would either of you happen to know another way of doing this?

Thanks again.


On Thursday, 7 September 2017 11:48:31 UTC+1, Antigoni Kaliontzopoulou wrote:
Hi Nils,

not sure what you mean by "normalizing" PCA results, do you want to center and scale the data? prcomp does not have, as far as I recall a "size" argument as your code suggests...

Anyway, if what you want to do is center and scale, yes, you can pass these prcomp arguments directly to plotTangentSpace, as the function uses prcomp under the hood. Caution is needed if you want to visualize the results in terms of shape variation, though, as centering shape data substracts the mean shape configuration from your coordinates. This means that after applying such a centering, your data will "loose" their geometric properties, and deformation grids will look weird. For visualization, you would need to add back the consensus to your pca data.

Not sure this is what you meant, though.
All the best,
Antigoni

On Thu, Sep 7, 2017 at 11:31 AM, Nils V <nilsva...@gmail.com> wrote:
Hi,
I'm not the best at R so I'm having a bit of trouble.

Is there anyway to normalize the PCA results from plotTangentSpace? Similar to using prcomp(x, size=true). Or is it already normalized?

I'm trying to perform a procrustes (using vegan package), comparing two seperate PCA results from prcomp and from plotTangentSpace on the same objects, but due to differences in PCA scale it ends up coming warped (see attached).

Any help would be appreciated!

Cheers,
Nils

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.



--


Antigoni Kaliontzopoulou

Assistant Researcher
CIBIO/InBIO, Centro de Investigação em Biodiversidade e Recursos Genéticos
University of Porto
Campus Agrário de Vairão, 4485-661 Vairão
PORTUGAL

http://antigonik.wix.com/akaliontzopoulou
http://cibio.up.pt/people/details/akaliont
http://aphylogenetics.wix.com/phylogenetics

On Thursday, 7 September 2017 11:48:31 UTC+1, Antigoni Kaliontzopoulou wrote:
Hi Nils,

not sure what you mean by "normalizing" PCA results, do you want to center and scale the data? prcomp does not have, as far as I recall a "size" argument as your code suggests...

Anyway, if what you want to do is center and scale, yes, you can pass these prcomp arguments directly to plotTangentSpace, as the function uses prcomp under the hood. Caution is needed if you want to visualize the results in terms of shape variation, though, as centering shape data substracts the mean shape configuration from your coordinates. This means that after applying such a centering, your data will "loose" their geometric properties, and deformation grids will look weird. For visualization, you would need to add back the consensus to your pca data.

Not sure this is what you meant, though.
All the best,
Antigoni

On Thu, Sep 7, 2017 at 11:31 AM, Nils V <nilsva...@gmail.com> wrote:
Hi,
I'm not the best at R so I'm having a bit of trouble.

Is there anyway to normalize the PCA results from plotTangentSpace? Similar to using prcomp(x, size=true). Or is it already normalized?

I'm trying to perform a procrustes (using vegan package), comparing two seperate PCA results from prcomp and from plotTangentSpace on the same objects, but due to differences in PCA scale it ends up coming warped (see attached).

Any help would be appreciated!

Cheers,
Nils

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.

Mike Collyer

unread,
Sep 7, 2017, 11:44:59 AM9/7/17
to geomorph-...@googlegroups.com
Nils,

If you are using Procrustes methods, I do not think standardizing the Procrustes residuals is a smart thing to do.  If visualizing the shapes of specimens is important, do not standardize the variables and for the vegan Procrustes rotation you wish to do, just realize that you can standardize the variables to get the PC scores, if you want, but the warpgrids will not make sense.  They might make more sense if you multiplied the coordinates by their standard deviations and added the mean shape, as Antigoni mentioned before.  But this does not seem necessary for the analysis you wish to do.

The warpgrids are based on mapping the reference configuration onto specimen configurations and correspond to a shape space that is not standardized.  I do not know of a theoretical treatment that standardizes shape spaces and do not wish to advocate this, for the purpose of visualizing shape variation.

Cheers!

Mike

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.

Adams, Dean [EEOBS]

unread,
Sep 7, 2017, 12:27:42 PM9/7/17
to geomorph-...@googlegroups.com

Nils,

 

To respond to your question and follow up on Mike’s comment:  the discussion of to standardize or not standardize variables for PCA typically comes up with ecological data or other datasets where individual variables are being treated multivariately. Sometimes, such data contain variables that may be in different units and/or scale. This matters because some variables may have larger variation than others due simply to the fact that they were measured in those different units or scale. In such cases, those variables with excessively large variation due to scaling would then have ‘undue’ influence on the directions of the eigenvectors. This may not be desirable, and so standardization is used. A rather silly example is if one trait is measured in millimeters and the rest in meters.  The trait in mm will be expected to have variation 1000 times greater than the other traits simply due to the scale of the values, and would thus ‘pull’ the dominant eigenvector in its direction. This may not be desirable (and in this case also avoidable).

 

That being said however, standardization should not be thought of as an automatic operation. For instance, some data may be in similar units and scale and still display large variance disparities between traits. In these cases, standardization is actually bad as it obliterates the very variance-covariance patterns one wishes to summarize in the data!  As always, thinking is encouraged before applying some operation (standardization in this case).

 

Now for the case of Procrustes residuals, these are in the same units, and are in appropriate relative scale to one another. So there is no need to standardize these for PCA at all.

 

Hope this helps,

 

Dean

 

Dr. Dean C. Adams

Professor

Department of Ecology, Evolution, and Organismal Biology

       Department of Statistics

Iowa State University

www.public.iastate.edu/~dcadams/

phone: 515-294-3834

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.

Mike Collyer

unread,
Sep 7, 2017, 12:47:17 PM9/7/17
to geomorph-...@googlegroups.com
One thing for our users to be careful of in this thread is the discussion of “Procrustes” methods.  In geomorph, gpagen does Procrustes superimposition of landmark configurations.  In vegan, the procrustes function performs a Procrustes rotation of one set of data to another.  This is typically done with ordination scores to see if two ordinations - e.g., PC projections - are similar.  A test is performed to ascertain whether the alignment is significant based on random alignments.  It is possible to perform a Procrustes rotation of e.g., shape data and behavior data.  Since these variables are measured with different units and different scales, scaling variables first might be wise.

I believe Nils is attempting something along these lines.

I recommend, however, using a two-block partial least squares analysis for this purpose.  It accomplishes the same goal without having to contrive reduced axes (Procrustes rotation is based on the smallest number of matching dimensions) or standardize variables.  Furthermore, the statistic is a correlation coefficient and the goal is to determine if data sets are correlated.  With the function in geomorph, the warp grids are also appropriate if some of the data are shape data.

Cheers!
Mike




Nils V

unread,
Sep 11, 2017, 5:22:24 AM9/11/17
to geomorph R package
Hi Mike,

I've looked at the two.b.pls command from geomorph. It seems that it requires two 3D arrays for comparison. One of my data sets (the non-geomorph one) was based on euclidean measurements, not landmarks. So I was unable to make it into a 3D array. Would you know anyway to work around this?

Cheers,
Nils
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.


 
-- 


Antigoni Kaliontzopoulou 

Assistant Researcher
CIBIO/InBIO, Centro de Investigação em Biodiversidade e Recursos Genéticos
University of Porto
Campus Agrário de Vairão, 4485-661 Vairão
PORTUGAL

http://antigonik.wix.com/akaliontzopoulou
http://cibio.up.pt/people/details/akaliont
http://aphylogenetics.wix.com/phylogenetics
-- 
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.
-- 
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.

Mike Collyer

unread,
Sep 11, 2017, 6:09:23 AM9/11/17
to geomorph-...@googlegroups.com
Hi Nils,

The function does not require 3D arrays.  It works with matrices.  Note the description from the function:

A1

A 3D array (p x k x n) containing GPA-aligned coordinates for the first block, or a matrix (n x variables)

A2

A 3D array (p x k x n) containing GPA-aligned coordinates for the second block, or a matrix (n x variables)

The function requires 3D arrays only if warpgrids are to be generated.

Mike

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.

Nils V

unread,
Sep 11, 2017, 6:48:44 AM9/11/17
to geomorph R package
That's great, apologies for not reading it properly. Thank you for all the help as well!

Kind regards,
Nils
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.

To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.
Reply all
Reply to author
Forward
0 new messages