eigenstrat: Calculate PCs similar to eigenstrat of genotype matrix

Description Usage Arguments Value Author(s) References Examples

Description

Takes a recoded (0,1,2,NA) matrix where SNPs are rows and a vector of minor allele frequencies for each row. Returns object with PCs, mu, and sigma values. Can handle NAs, but simply removes any rows containing NA, so NA should be imputed first.

Usage

1
eigenstrat(W=genoMat,maf=snpInfo$MAF)

Arguments

geno

Matrix where SNPs are rows and lines are columns, no metadata columns. Coded as 0,1,2,NA. NA rows will be removed, so most likely should be imputed first.

Value

Returns an eigenstrat object

Author(s)

Greg Ziegler

References

This was modified from http://www.popgen.dk/software/index.php/Rscripts

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#impute all missing to 0
genoMat <- as.matrix(genotype)
class(genoMat) <- "numeric"
genoMat[which(is.na(genoMat))] <- 0

####Genotype file should be in 0, 1, 2 coding
###rows are snps and columns are individuals

e<-eigenstrat(genoMat)
pdf("../results/5.Eigenstrat.structure.PC1vsPC2.and.VarianceExplained.pdf")
plot(e,xlab="PC1",ylab="PC2")
barplot(height=e$values[1:10]/sum(e$values))
dev.off()
structData <- e$vectors[,1:10]
rownames(structData) <- colnames(genotype)
varExplained <- e$values[1:10]/sum(e$values)

gziegler/ionomicsUtils documentation built on June 20, 2019, 8:04 p.m.