##' Computes Hellinger distance for each pair of columns from the input
##' data.
##' @title Hellinger distance computation
##' @param sr a matrix or data.frame with the transcript relative
##' expression for each sample (column).
##' @return a matrix with the pairwise distance between samples.
##' @author Jean Monlong
##' @keywords internal
hellingerDist <- function(sr)
{
k <- dim(sr)[2]
interdist <- matrix(data = 0, nrow = k, ncol = k)
for(i in 1:k) {
for(j in 1:i) {
interdist[i, j] <- hellingerDist.p(sr[, i], sr[, j])
}
}
interdist <- interdist + t(interdist)
colnames(interdist) <- rownames(interdist) <- colnames(sr)
non.na <- !is.na(diag(interdist))
interdist <- interdist[non.na, non.na]
return(stats::as.dist(interdist))
}
hellingerDist.p <- function(x1, x2)
{
a <- (sqrt(x1) - sqrt(x2))
b <- sqrt(sum(a * a))
return(b)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.