-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathREADME.Rmd
More file actions
90 lines (72 loc) · 3.48 KB
/
README.Rmd
File metadata and controls
90 lines (72 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# PCAtest
<!-- badges: start -->
<!-- badges: end -->
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.
## Installation
You can install the released (version 0.02) and the development versions from [GitHub]
(https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("arleyc/PCAtest")
```
## Examples
```{r example1}
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)
```
```{r example2}
#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)
```
```{r example3}
#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)
```
```{r example4}
#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)
```
## Testing
[Unit testing with testthat (https://testthat.r-lib.org/)](tests/testthat/testthat.md)
## References
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.\
## Citation
Camargo, A. (2022) PCAtest: Testing the statistical significance of Principal Component Analysis in R. PeerJ 10: e12967. doi: 10.7717/peerj.12967