Skip to content

Instantly share code, notes, and snippets.

@xwu
Created July 22, 2014 22:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xwu/ddf04c763c80ca418ccc to your computer and use it in GitHub Desktop.
Save xwu/ddf04c763c80ca418ccc to your computer and use it in GitHub Desktop.
Principal component analysis of gene expression microarray datasets
my.data.frame <- read.delim("tab_delimited_file_with_probeset_ids_in_first_column.txt", row.names=1)
my.data.matrix <- as.matrix(my.data.frame)
# PCA by sample:
# center each gene (mean) without scaling
# scale each sample (root mean square) without centering
# transpose the matrix to PCA by sample instead of by gene
a <- scale(t(my.data.matrix), center=TRUE, scale=FALSE)
b <- scale(t(a), center=FALSE, scale=TRUE)
my.pca <- prcomp(t(b), center=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment