Hi all, I am using the vegan package to run a prcincipal components analysis on forest structural variables (tree density, basal area, average height, regeneration density) in R. However, I could not find out how to extract factor loadings (correlations of each variable with each pca axis), as is straightforwar in princomp. Do anyone know how to do that? Moreover, do anyone knows a function r package that produces rotated-pca and biplots? Most packages I found did only one of these tasks (princomp, psych, vegan). Thanks a lot, Alexandre Dr. Alexandre F. Souza Programa de P??s-Gradua????o em Biologia: Diversidade e Manejo da Vida Silvestre Universidade do Vale do Rio dos Sinos (UNISINOS) Av. UNISINOS 950 - C.P. 275, S??o Leopoldo 93022-000, RS - Brasil Telefone: (051)3590-8477 ramal 1263 Skype: alexfadigas afsouza at unisinos.br http://www.unisinos.br/laboratorios/lecopop -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo.
Hi all, I am using the vegan package to run a prcincipal components analysis on forest structural variables (tree density, basal area, average height, regeneration density) in R. However, I could not find out how to extract factor loadings (correlations of each variable with each pca axis), as is straightforwar in princomp. Do anyone know how to do that? Moreover, do anyone knows a function r package that produces rotated-pca and biplots? Most packages I found did only one of these tasks (princomp, psych, vegan). Thanks a lot, Alexandre Dr. Alexandre F. Souza Programa de P??s-Gradua????o em Biologia: Diversidade e Manejo da Vida Silvestre Universidade do Vale do Rio dos Sinos (UNISINOS) Av. UNISINOS 950 - C.P. 275, S??o Leopoldo 93022-000, RS - Brasil Telefone: (051)3590-8477 ramal 1263 Skype: alexfadigas afsouza at unisinos.br http://www.unisinos.br/laboratorios/lecopop -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo.
On Wednesday 30 of June 2010 23:02:09 afsouza at unisinos.br wrote:> Hi all, > > I am using the vegan package to run a prcincipal components analysis > on forest structural variables (tree density, basal area, average > height, regeneration density) in R. > > However, I could not find out how to extract factor loadings > (correlations of each variable with each pca axis), as is straightforwar > in princomp. > > Do anyone know how to do that? > > Moreover, do anyone knows a function r package that produces > rotated-pca and biplots? Most packages I found did only one of these > tasks (princomp, psych, vegan). > > Thanks a lot, > AlexandreHi Alexandre. I haven't used the vegan package. But using princomp() and/or prcomp() is really easy. Easy is also the extraction of the loadings. Just check the structure of the result of princomp() to find the "loadings" or the result of prcomp() to find the "rotation" ( which is the same as the loadings in princomp() ). For plotting you might want to have a look at the plotpc R package. It's something I really like (and have customised it a lot to suit my needs of plotting bivariate rotated axes (=the principal components) of a given data set using the prcomp R function and even more). Don't know though if this is what you are looking for. ( ...my custom version however is not ready for a generic use. It would take to somebody to spend more time on it to remove hardcoded stuff and figure out smart automatic ways to handle co-plotting scaled and non-scaled axes (as a result of scaled=standardised and non-scaled=unstandardised PCA) on the same plot.) Also interesting is the smoothScatter functions that "produces a smoothed color density representation of the scatterplot, obtained through a kernel density estimate." It used "densCols" to "produce a vector containing colors which encode the local densities at each point in a scatterplot." Very interesting if the data-matrix to be transformed is large. Nikos
On Wed, 2010-06-30 at 18:02 -0300, afsouza at unisinos.br wrote:> Hi all, > > I am using the vegan package to run a prcincipal components analysis > on forest structural variables (tree density, basal area, average > height, regeneration density) in R. > > However, I could not find out how to extract factor loadings > (correlations of each variable with each pca axis), as is straightforwar > in princomp. > > Do anyone know how to do that?It is easier than I thought when I answered your Q on ECOLOG-L the other day ;-) If ord is your fitted PCA ordination done using rda() from vegan, then we just need to extract the *unscaled* species scores to get the same things as is given by loadings() on a princomp ordination or the $rotation from a prcomp ordination require(vegan) foo <- princomp(USArrests, cor = TRUE) FOO <- prcomp(USArrests, scale = TRUE) bar <- rda(USArrests, scale = TRUE) loadings(foo) with(FOO, rotation) scores(bar, choices = 1:4, display = "species", scaling = 0)> Moreover, do anyone knows a function r package that produces > rotated-pca and biplots? Most packages I found did only one of these > tasks (princomp, psych, vegan).I'm not sure what you mean here; biplot() is a convenience wrapper method for rda() ordinations that produces a biplot of the PCA ordination. The plot methods for rda() objects allow you to create a biplot by hand if you want or just plot one set of scores. The biplot() method just tries to simplify this process. As is typical in ecology though, we want to scale sites or species to best represent relationships between sites or between species, so you need to choose the scaling most appropriate for your data/question. Scaling = 3 is usually a good compromise. More about scalings in vegan and prcomp/princomp can be found in the design decisions vignette: http://cran.r-project.org/web/packages/vegan/vignettes/decision-vegan.pdf Can you explain what you mean by "rotated-pca"? PCA is just a rotation of the data and that is what vegan does and plots. This may just be an issue of terminology, so if you can explain or point me to a reference that describes what you want, I'll look into it some more. HTH G> > Thanks a lot, > > Alexandre > > > > Dr. Alexandre F. Souza > Programa de P?s-Gradua??o em Biologia: Diversidade e Manejo da Vida > Silvestre > Universidade do Vale do Rio dos Sinos (UNISINOS) > Av. UNISINOS 950 - C.P. 275, S?o Leopoldo 93022-000, RS - Brasil > Telefone: (051)3590-8477 ramal 1263 > Skype: alexfadigas > afsouza at unisinos.br > http://www.unisinos.br/laboratorios/lecopop > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%