Description Usage Arguments Value Author(s) References Examples
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.
1 | eigenstrat(W=genoMat,maf=snpInfo$MAF)
|
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. |
Returns an eigenstrat object
Greg Ziegler
This was modified from http://www.popgen.dk/software/index.php/Rscripts
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.