mkatari-bioinformatics-august-2013-clustering
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
mkatari-bioinformatics-august-2013-clustering [2014/12/11 14:16] – mkatari | mkatari-bioinformatics-august-2013-clustering [2014/12/11 14:55] – [K-means] mkatari | ||
---|---|---|---|
Line 67: | Line 67: | ||
====== K-means ====== | ====== K-means ====== | ||
+ | The K-means method uses euclidean distance to measure distance. Since in biology we are more interested in gene expression profiles instead of magnitude of expression levels, let's scale our data so that the mean of the expression values is 0 and the expression values will be the standard deviations away from the mean. | ||
+ | |||
+ | < | ||
+ | # this function takes an vector to be calculated. | ||
+ | scaleData <- function(x) { | ||
+ | x = as.numeric(x) | ||
+ | meanx = mean(x) | ||
+ | sdx = sd(x) | ||
+ | y = (x-meanx)/ | ||
+ | return(y) | ||
+ | } | ||
+ | |||
+ | #we need to transpose it because apply function returns the genes as different columns. | ||
+ | scaledSigGenes = t(apply(sigGenes.normalized, | ||
+ | colnames(scaledSigGenes)=colnames(sigGenes.normalized) | ||
+ | |||
+ | </ | ||
mkatari-bioinformatics-august-2013-clustering.txt · Last modified: 2015/06/17 13:26 by mkatari