PCAtest | R Documentation |
PCAtest uses random permutations to build null distributions for several statistics of a PCA analysis: 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.
PCAtest(
x,
nperm = 1000,
nboot = 1000,
alpha = 0.05,
indload = TRUE,
varcorr = FALSE,
counter = TRUE,
plot = TRUE
)
x |
A matrix or dataframe with variables in the columns and the observations in the rows. |
nperm |
Number of random permutations to build null distributions of the statistics. |
nboot |
Number of bootstrap replicates to build 95%-confidence intervals of the observed statistics. |
alpha |
Nominal alpha level for statistical tests. |
indload |
A logical indicating whether to calculate the index loadings of the variables with the significant PCs. |
varcorr |
A logical indicating whether to calculate the correlations of the variables with the significant PCs. |
counter |
A logical specifying whether to show the progress of the random sampling (bootstrap and permutations) on the screen. |
plot |
A logical specifying whether to plot the null distributions, observed statistics, and 95%-confidence intervals of statistics based on random permutation and bootstrap resampling. |
PCAtest uses the function stats::prcomp to run a PCA using the arguments scale = TRUE and center = TRUE. PCAtest plots four types of graphs in a single page: (1) a histogram showing the null distribution and the observed value of the Psi statistic, (2) a histogram showing the null distribution and the observed value of the Phi statistic, (3) a bar plot of the percentage of explained variance of each PC1, PC2, ..., etc., showing the sampling variance based on bootstrap replicates and random permutations with 95%-confidence intervals, and (4) a bar plot of the index of the loadings of each observed variable for PC1, showing the sampling variance of bootstrap replicates and random permutations with 95%- confidence intervals. If more than one PC is significant, additional plots for the index of the loadings are shown in as many new pages as necessary given the number of significant PCs. If the PCA is not significant, based on the Psi and Phi testing results, only histograms (1) and (2) are shown.
An object of class “list” with the following elements:
The observed Psi statistic.
The observed Phi statistic.
The null distribution of Psi values.
The null distribution of Phi values.
The percentage of variance explained by each PC based on the observed data.
The percentage of variance explained by each PC based on the bootstrapped data.
Confidence intervals of the percentage of variance explained by each PC based on the bootstrapped data.
The percentage of variance explained by each PC based on the randomized data.
Confidence intervals of the percentage of variance explained by each PC based on the randomized data.
The index of the loadings of the observed data.
The index of the loadings of the bootstrapped data.
Confidence intervals of the index of the loadings based on the bootstrapped data.
The index of the loadings based on the randomized data.
Confidence intervals of the index of the loadings based on the randomized data.
If varcorr=TRUE, the correlations of the observed variables with each significant PC.
If varcorr=TRUE, the correlations of the observed variables with each significant PC based on the bootstrapped data.
If varcorr=TRUE, the confidence intervals of the correlations of the variables with each significant PC based on the bootstrapped data.
If varcorr=TRUE, the correlations of the observed variables with each significant PC based on randomized data.
If varcorr=TRUE, the confidence intervals of the correlations of the variables with each significant PC based on randomized data.
Arley Camargo
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.
Ringnér, M. (2008) What is principal component analysis? Nature Biotechnology, 26, 303–304.
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. https://doi.org/10.1111/2041- 210X.13568.
#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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.