knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of PCAtest is to evaluate the overall significance of a PCA, of each PC axis, and of the contributions of each observed variable to the significant axes based on permutation-based statistical tests. PCAtest uses random permutations to build null distributions for several statistics of a PCAanalysis: Psi (Vieira 2012),Phi (Gleason and Staelin 1975), the rank-of-roots (ter Braak 1988), the index of the loadings (Vieira 2012), and the correlations of the PC with the variables (Jackson 1991). Comparing these distributions with the observed values of the statistics, the function tests: (1) the hypothesis that there is more correlational structure among the observed variables than expected by random chance, (2) the statistical significance of each PC, and (3) the contribution of each observed variable to each significant PC. The function also calculates the sampling variance around mean observed statistics based on bootstrap replicates.
You can install the released (version 0.02) and the development versions from [GitHub] (https://github.com/) with:
# install.packages("devtools") devtools::install_github("arleyc/PCAtest")
library(PCAtest) # PCA analysis of five uncorrelated (r=0) variables library(MASS) mu <- rep(0,5) Sigma <- matrix(c(rep(c(1,0,0,0,0,0),4),1),5) ex0 <- mvrnorm(100, mu = mu, Sigma = Sigma ) result<-PCAtest(ex0, 100, 100, 0.05, varcorr=FALSE, counter=FALSE, plot=TRUE)
#PCA analysis of five correlated (r=0.25) variables Sigma <- matrix(c(rep(c(1,0.25,0.25,0.25,0.25,0.25),4),1),5) ex025 <- mvrnorm(100, mu = mu, Sigma = Sigma ) result<-PCAtest(ex025, 100, 100, 0.05, varcorr=FALSE, counter=FALSE, plot=TRUE)
#PCA analysis of five correlated (r=0.5) variables Sigma <- matrix(c(rep(c(1,0.5,0.5,0.5,0.5,0.5),4),1),5) ex05 <- mvrnorm(100, mu = mu, Sigma = Sigma ) result<-PCAtest(ex05, 100, 100, 0.05, varcorr=FALSE, counter=FALSE, plot=TRUE)
#PCA analysis of seven morphological variables from 29 ant species (from # Wong and Carmona 2021, https://doi.org/10.1111/2041-210X.13568) data("ants") result<-PCAtest(ants, 100, 100, 0.05, varcorr=FALSE, counter=FALSE, plot=TRUE)
Unit testing with testthat (https://testthat.r-lib.org/)
Gleason, T. C. and Staelin R. (1975) A proposal for handling missing data. Psychometrika, 40, 229–252.\ Jackson, J. E. (1991) A User’s Guide to Principal Components. John Wiley & Sons, New York, USA.\ ter Braak, C. F. J. (1990) Update notes: CANOCO (version 3.1). Agricultural Mattematic Group, Report LWA-88-02, Wagningen, Netherlands.\ Vieira, V. M. N. C. S. (2012) Permutation tests to estimate significances on Principal Components Analysis. Computational Ecology and Software, 2, 103–123.\ Wong, M. K. L. and Carmona, C. P. (2021) Including intraspecific trait variability to avoid distortion of functional diversity and ecological inference: Lessons from natural assemblages. Methods in Ecology and Evolution, 12, 946-957.\
Camargo, A. (2022) PCAtest: Testing the statistical significance of Principal Component Analysis in R. PeerJ 10: e12967. doi: 10.7717/peerj.12967
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.