Created
June 30, 2016 18:15
-
-
Save stephenturner/96a78f5146f085afb837d0bcc87bcb40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Performs principal components analysis on an ExpressionSet | |
| eset_pca <- function (eset) { | |
| mypca <- prcomp(t(na.omit(exprs(eset)))) | |
| pca <- as.data.frame(mypca$x) | |
| pc1var <- round(summary(mypca)$importance[2,1]*100, digits<-1) | |
| pc2var <- round(summary(mypca)$importance[2,2]*100, digits<-1) | |
| pc1lab <- paste0("PC1 (",as.character(pc1var),"%)") | |
| pc2lab <- paste0("PC1 (",as.character(pc2var),"%)") | |
| out <- merge(pData(eset), pca, by<-"row.names") %>% | |
| dplyr::rename(id<-Row.names) | |
| attr(out, "pc1lab") <- pc1lab | |
| attr(out, "pc2lab") <- pc2lab | |
| out | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment