Perform tracy-widom tests on a set of eigenvalues to determine the number of
significative eigenvalues and calculate the percentage of variance explained
by each principal component. For an example, see pca.
Usage
tracy.widom (object)
Arguments
object
a pcaProject object.
Value
tracy.widom returns a list containing the following components:
eigenvalues
The sorted input vector of eigenvalues (by descreasing order).
twstats
The vector of tracy-widom statistics.
pvalues
The vector of p-values associated with each eigenvalue.
effecn
The vector of effective sizes.
percentage
The vector containing the percentage of variance
explained by each principal component.
Author(s)
Eric Frichot
References
Tracy CA and Widom H. (1994). Level spacing distributions and the bessel
kernel. Commun Math Phys. 161 :289–309.
Patterson N, Price AL and Reich D. (2006). Population structure and
eigenanalysis. PLoS Genet. 2 :20.
See Also
pcalfmm.datalfmm
Examples
# Creation of the genotype file "genotypes.lfmm"
# with 1000 SNPs for 165 individuals.
data("tutorial")
write.lfmm(tutorial.R,"genotypes.lfmm")
#################
# Perform a PCA #
#################
# run of PCA
# Available options, K (the number of PCs calculated),
# center and scale.
# Creation of genotypes.pcaProject - the pcaProject object.
# a directory genotypes.pca containing:
# Create files: genotypes.eigenvalues - eigenvalues,
# genotypes.eigenvectors - eigenvectors,
# genotypes.sdev - standard deviations,
# genotypes.projections - projections,
# Create a pcaProject object: pc.
pc = pca("genotypes.lfmm", scale = TRUE)
#############################
# Perform Tracy-Widom tests #
#############################
# Perfom Tracy-Widom tests on all eigenvalues.
# Create file: genotypes.tracyWidom - tracy-widom test information,
# in the directory genotypes.pca/.
tw = tracy.widom(pc)
# Plot the percentage of variance explained by each component.
plot(tw$percentage)
# Display the p-values for the Tracy-Widom tests.
tw$pvalues
# remove pca Project
remove.pcaProject("genotypes.pcaProject")
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(LEA)
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/LEA/main_tracyWidom.Rd_%03d_medium.png", width=480, height=480)
> ### Name: tracy.widom
> ### Title: Tracy-Widom test for eigenvalues
> ### Aliases: tracy.widom
> ### Keywords: pca
>
> ### ** Examples
>
> # Creation of the genotype file "genotypes.lfmm"
> # with 1000 SNPs for 165 individuals.
> data("tutorial")
> write.lfmm(tutorial.R,"genotypes.lfmm")
[1] "genotypes.lfmm"
>
> #################
> # Perform a PCA #
> #################
>
> # run of PCA
> # Available options, K (the number of PCs calculated),
> # center and scale.
> # Creation of genotypes.pcaProject - the pcaProject object.
> # a directory genotypes.pca containing:
> # Create files: genotypes.eigenvalues - eigenvalues,
> # genotypes.eigenvectors - eigenvectors,
> # genotypes.sdev - standard deviations,
> # genotypes.projections - projections,
> # Create a pcaProject object: pc.
> pc = pca("genotypes.lfmm", scale = TRUE)
[1] "******************************"
[1] " Principal Component Analysis "
[1] "******************************"
summary of the options:
-n (number of individuals) 50
-L (number of loci) 400
-K (number of principal components) 50
-x (genotype file) /home/ddbj/DataUpdator-rgm3/target/genotypes.lfmm
-a (eigenvalue file) /home/ddbj/DataUpdator-rgm3/target/genotypes.pca/genotypes.eigenvalues
-e (eigenvector file) /home/ddbj/DataUpdator-rgm3/target/genotypes.pca/genotypes.eigenvectors
-d (standard deviation file) /home/ddbj/DataUpdator-rgm3/target/genotypes.pca/genotypes.sdev
-p (projection file) /home/ddbj/DataUpdator-rgm3/target/genotypes.pca/genotypes.projections
-s data centered and scaled
>
> #############################
> # Perform Tracy-Widom tests #
> #############################
>
> # Perfom Tracy-Widom tests on all eigenvalues.
> # Create file: genotypes.tracyWidom - tracy-widom test information,
> # in the directory genotypes.pca/.
> tw = tracy.widom(pc)
[1] "*******************"
[1] " Tracy-Widom tests "
[1] "*******************"
summary of the options:
-n (number of eigenvalues) 50
-i (input file) /home/ddbj/DataUpdator-rgm3/target/genotypes.pca/genotypes.eigenvalues
-o (output file) /home/ddbj/DataUpdator-rgm3/target/genotypes.pca/genotypes.tracywidom
>
> # Plot the percentage of variance explained by each component.
> plot(tw$percentage)
>
> # Display the p-values for the Tracy-Widom tests.
> tw$pvalues
[1] 8.000e-09 8.000e-09 8.000e-09 1.503e-04 3.152e-02 4.215e-01 6.565e-01
[8] 6.859e-01 6.738e-01 9.363e-01 7.937e-01 9.827e-01 9.709e-01 9.425e-01
[15] 9.240e-01 8.119e-01 9.734e-01 9.870e-01 9.996e-01 9.972e-01 9.973e-01
[22] 9.904e-01 9.959e-01 9.835e-01 9.953e-01 9.777e-01 9.801e-01 9.354e-01
[29] 8.465e-01 9.499e-01 8.092e-01 8.500e-01 7.492e-01 9.638e-01 9.114e-01
[36] 8.908e-01 9.402e-01 9.173e-01 7.407e-01 8.460e-01 8.067e-01 7.215e-01
[43] 4.396e-01 2.428e-01 6.246e-01 2.789e-01 6.168e-01 3.909e-01 7.257e-01
>
> # remove pca Project
> remove.pcaProject("genotypes.pcaProject")
[1] TRUE
>
>
>
>
>
> dev.off()
null device
1
>