#' Calculate CLR variances of each feature
#'
#' @param matrix matrix containing CLR values
#' @param sorted logical vector: should variance values be returned in
#' decreasing order
#'
#' @return named vector
#' @export
#'
#' @examples
#' milk_clr <- t(apply(mammalsmilk, 1, function(x){log(x) - mean(log(x))}))
#' clr_variance(milk_clr)
#'
#' # Show 5 genes with highest CLR variance across dataset
#' clr_variance(sewage_clr, sorted = TRUE)[1:5]
clr_variance <- function(matrix, sorted = F) {
tmp_vars <- apply(matrix, 2, stats::var) * (nrow(matrix) - 1) / nrow(matrix)
if(sorted) return(sort(tmp_vars, decreasing = T))
tmp_vars
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.