Description Usage Arguments Value Author(s) See Also Examples
The pca
function performs a principal component analysis
of a genotypic matrix encoded in one of the following formats:
lfmm
, geno
, ancestrymap
,
ped
or vcf
.
The pca
function computes eigenvalues, eigenvectors, and standard deviations
for all principal components and the projections of individuals
on each component. Thepca
function returns an object of class
"pcaProject" containing the output data and the input parameters.
1 |
input.file |
A character string containg the path to the genotype input file,
a genotypic matrix in the |
K |
An integer corresponding to the number of principal components calculated. By default, all principal components are calculated. |
center |
A boolean option. If TRUE, the data matrix is centered (default: TRUE). |
scale |
A boolean option. If TRUE, the data matrix is centered and scaled (default: FALSE). |
pca
returns an object of class pcaProject
containing the
following components:
eigenvalues |
The vector of eigenvalues. |
eigenvectors |
The matrix of eigenvectors (one column for each eigenvector). |
sdev |
The vector of standard deviations. |
projections |
The matrix of projections (one column for each projection). |
The following methods can be applied to the object of class pcaProject returned
by pca
:
plot |
Plot the eigenvalues. |
show |
Display information on analysis. |
summary |
Summarize analysis. |
tracy.widom |
Perform Tracy-Widom tests for eigenvalues. |
load.pcaProject(file.pcaProject) |
Load the file containing a pcaProject object and return the pcaProject object. |
remove.pcaProject(file.pcaProject) |
Erase a |
export.pcaProject(file.pcaProject) |
Create a zip file containing the full |
import.pcaProject(file.pcaProject) |
Import and load an |
Eric Frichot
lfmm.data
snmf
lfmm
lfmm2
tutorial
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 91 92 93 94 | # Create a genotype file "genotypes.lfmm"
# with 1000 SNPs for 165 individuals.
data("tutorial")
write.lfmm(tutorial.R,"genotypes.lfmm")
#################
# Perform PCA #
#################
# run PCA
# Available options: K (the number of PCs),
# center and scale.
# Creation of genotypes.pcaProject - the pcaProject object.
# a directory genotypes.pca containing:
# genotypes.eigenvalues - eigenvalues,
# genotypes.eigenvectors - eigenvectors,
# genotypes.sdev - standard deviations,
# genotypes.projections - projections,
# Create a pcaProject object: pc.
pc <- pca("genotypes.lfmm", scale = TRUE)
#######################
# Display information #
#######################
# Display information on analysis.
show(pc)
# Summarize analysis.
summary(pc)
#####################
# Graphical outputs #
#####################
par(mfrow=c(2,2))
# Plot eigenvalues.
plot(pc, lwd=5, col="blue", cex = .7, xlab=("Factors"), ylab="Eigenvalues")
# PC1-PC2 plot.
plot(pc$projections)
# PC3-PC4 plot.
plot(pc$projections[,3:4])
# Plot standard deviations.
plot(pc$sdev)
#############################
# Perform Tracy-Widom tests #
#############################
# Perfom Tracy-Widom tests for 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)
# Show p-values for the Tracy-Widom tests.
tw$pvalues
##########################
# Manage a pca project #
##########################
# All the project files for a given input matrix are
# automatically saved into a pca project directory.
# The name of the pcaProject file is the same name as
# the name of the input file with a .pcaProject extension
# ("genotypes.pcaProject").
# The name of the pcaProject directory is the same name as
# the name of the input file with .pca extension ("genotypes.pca/")
# There is only one pca Project for each input file including all the runs.
# An pcaProject can be load in a different session.
project = load.pcaProject("genotypes.pcaProject")
# An pcaProject can be exported to be imported in another directory
# or in another computer
export.pcaProject("genotypes.pcaProject")
dir.create("test", showWarnings = TRUE)
#import
newProject = import.pcaProject("genotypes_pcaProject.zip", "test")
# remove
remove.pcaProject("test/genotypes.pcaProject")
# A pcaProject can be erased.
# Caution: All the files associated with the project will be removed.
remove.pcaProject("genotypes.pcaProject")
|
[1] "genotypes.lfmm"
[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) /work/tmp/genotypes.lfmm
-a (eigenvalue file) /work/tmp/genotypes.pca/genotypes.eigenvalues
-e (eigenvector file) /work/tmp/genotypes.pca/genotypes.eigenvectors
-d (standard deviation file) /work/tmp/genotypes.pca/genotypes.sdev
-p (projection file) /work/tmp/genotypes.pca/genotypes.projections
-s data centered and scaled
* pca class *
project directory: /work/tmp/
pca result directory: genotypes.pca/
input file: genotypes.lfmm
eigenvalue file: genotypes.eigenvalues
eigenvector file: genotypes.eigenvectors
standard deviation file: genotypes.sdev
projection file: genotypes.projections
pcaProject file: genotypes.pcaProject
number of individuals: 50
number of loci: 400
number of principal components: 50
centered: TRUE
scaled: TRUE
Importance of components:
PC1 PC2 PC3 PC4 PC5
Standard deviation 6.4135800 5.78728000 4.15808000 3.69458000 3.47388000
Proportion of Variance 0.1049337 0.08544031 0.04410613 0.03482123 0.03078531
Cumulative Proportion 0.1049337 0.19037400 0.23448013 0.26930135 0.30008666
PC6 PC7 PC8 PC9 PC10
Standard deviation 3.31251000 3.23157000 3.18106000 3.13701000 3.0478600
Proportion of Variance 0.02799169 0.02664041 0.02581408 0.02510419 0.0236976
Cumulative Proportion 0.32807835 0.35471876 0.38053284 0.40563703 0.4293346
PC11 PC12 PC13 PC14 PC15
Standard deviation 3.03857000 2.94752000 2.92203000 2.8995500 2.86908000
Proportion of Variance 0.02355332 0.02216296 0.02178128 0.0214474 0.02099903
Cumulative Proportion 0.45288795 0.47505092 0.49683219 0.5182796 0.53927863
PC16 PC17 PC18 PC19 PC20
Standard deviation 2.85347000 2.77617000 2.73353000 2.66595000 2.65867000
Proportion of Variance 0.02077123 0.01966097 0.01906163 0.01813082 0.01803199
Cumulative Proportion 0.56004985 0.57971082 0.59877246 0.61690328 0.63493527
PC21 PC22 PC23 PC24 PC25
Standard deviation 2.63015000 2.61658000 2.57644000 2.56496000 2.5182600
Proportion of Variance 0.01764714 0.01746546 0.01693383 0.01678322 0.0161776
Cumulative Proportion 0.65258241 0.67004787 0.68698170 0.70376492 0.7199425
PC26 PC27 PC28 PC29 PC30
Standard deviation 2.50940000 2.47612000 2.46346000 2.44649000 2.38631000
Proportion of Variance 0.01606408 0.01564077 0.01548123 0.01526873 0.01452669
Cumulative Proportion 0.73600661 0.75164737 0.76712860 0.78239732 0.79692401
PC31 PC32 PC33 PC34 PC35
Standard deviation 2.38020000 2.33529000 2.3108400 2.23289000 2.21740000
Proportion of Variance 0.01445245 0.01391225 0.0136224 0.01271893 0.01254301
Cumulative Proportion 0.81137646 0.82528871 0.8389111 0.85163004 0.86417305
PC36 PC37 PC38 PC39 PC40
Standard deviation 2.18767000 2.14222000 2.11608000 2.10842000 2.05300000
Proportion of Variance 0.01220898 0.01170689 0.01142296 0.01134046 0.01075204
Cumulative Proportion 0.87638203 0.88808892 0.89951188 0.91085234 0.92160438
PC41 PC42 PC43 PC44 PC45
Standard deviation 2.02122000 1.9917300 1.975050000 1.93240000 1.821420000
Proportion of Variance 0.01042174 0.0101199 0.009951123 0.00952597 0.008463215
Cumulative Proportion 0.93202612 0.9421460 0.952097138 0.96162311 0.970086323
PC46 PC47 PC48 PC49
Standard deviation 1.808260000 1.715340000 1.697050000 1.622970000
Proportion of Variance 0.008341276 0.007506123 0.007346837 0.006719439
Cumulative Proportion 0.978427600 0.985933723 0.993280561 1.000000000
PC50
Standard deviation 8.966450e-07
Proportion of Variance 2.050949e-15
Cumulative Proportion 1.000000e+00
[1] "*******************"
[1] " Tracy-Widom tests "
[1] "*******************"
summary of the options:
-n (number of eigenvalues) 50
-i (input file) /work/tmp/genotypes.pca/genotypes.eigenvalues
-o (output file) /work/tmp/genotypes.pca/genotypes.tracywidom
[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
adding: genotypes.pcaProject (deflated 60%)
adding: genotypes.pca/ (stored 0%)
adding: genotypes.pca/genotypes.tracywidom (deflated 52%)
adding: genotypes.pca/genotypes.projections (deflated 55%)
adding: genotypes.pca/genotypes.sdev (deflated 54%)
adding: genotypes.pca/genotypes.eigenvectors (deflated 60%)
adding: genotypes.pca/genotypes.eigenvalues (deflated 47%)
adding: genotypes.lfmm (deflated 89%)
An export of the pca project hase been created: genotypes_pcaProject.zip
The project has been imported into directory, test
[1] TRUE
[1] TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.