Description Usage Arguments Value Author(s) Examples
This function takes a matrix with with multiple samples per subclass and converts these to mean (or other metric) and sd values per class. Effectively it is just a wrapper for a few functions of the matrixStats package to combine the results for multiple classes. I.e. the same can easily be achieved by for instance rbinding two results from colMedians with two different row subsets
1 2 3 | shrink_matrix(DataMatrix, subclasses_list = NULL,
ignore_missing_values = TRUE, labels = NULL,
feature_orientation = "columns", metric = "median")
|
DataMatrix |
A matrix with feature groups as columns and samples for rows. |
labels |
A vector of labels which can be used to group the samples together in subclasses. This attribute is necessary if 'subclasses.list' consists of character or factor entries. |
metric |
The metric to be used, can be any of 'mean', 'median', 'max', 'min', 'var' or 'sd'. |
subclasses.list |
A list with either A) in each list entry a number of integers or numerics corresponding to the rows that form the subclasses to be checked, or B) in each list entry characters or factors corresponding to those found in the 'labels' attribute. |
ignore.missing.values |
Whether to ignore the missing values. If set to FALSE the calculation of the median intensities will result in a lot 'NAs' or 'NaNs' |
feature.orientation |
Indicates whether the features can be found in the columns (default) or in the rows. With the default setting every row corresponds to a sample, and every column to a feature/group |
Shrunken.matrix The shrunken matrix
Charlie Beirnaert, charlie.beirnaert@uantwerpen.be
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #Generate random matrix
testmatrix <- matrix(runif(n=90), nrow = 9, ncol = 10)
sample_groups <- c(rep("A",3), rep("B",3), rep("C",3))
subclasses <- as.list(unique(c(rep("A",3), rep("B",3), rep("C",3))))
Shrunken_matrix = shrink.matrix(DataMatrix = testmatrix,
subclasses.list = subclasses,
labels = sample_groups,
metric = "median")
#Note that the exact same result can be obtained with the following
library(matrixStats)
Shrunken_matrix2 = rbind(matrixStats::colMedians(testmatrix,
rows = which(sample_groups == subclasses[[1]]),
na.rm = TRUE),
matrixStats::colMedians(testmatrix,
rows = which(sample_groups == subclasses[[2]]),
na.rm = TRUE),
matrixStats::colMedians(testmatrix,
rows = which(sample_groups == subclasses[[3]]),
na.rm = TRUE))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.