#' affected.rows function
#'
#' This is one of a few functions created by Joe Cauteruccio, Jessie Li, Andrew West of Yale University that are used together to create the hclust_eval() function.
#' @param object.merge The merge value produced by hclust(). This is an n-1 by 2 matrix that descirbes merging of cluster at every step of clustering, with negative values meaning that observations were merged at the stage and not before. From documentation: "Thus negative entries in merge indicate agglomerations of singletons, and positive entries indicate agglomerations of non-singletons."
#'
#'@keywords affected.rows
#'@export
affected.rows <- function(object.merge){
x <- object.merge
list.affected.rows <- list()
tot.cat <- nrow(x)+1
cluster.mat <- matrix(0, nrow=nrow(x), ncol=tot.cat)
cluster.mat[nrow(x), -x[1, ]] <- 1
for (i in 2:nrow(x)){
cluster.mat[tot.cat-i, ] <- cluster.mat[tot.cat+1-i, ]
if (sum(sign(x[i, ])) == -2) cluster.mat[tot.cat-i, -x[i,]] <- i
if (sum(sign(x[i, ])) == 0){
cluster.mat[tot.cat-i, -x[i, 1]] <- x[i, 2]
cluster.mat[tot.cat-i, cluster.mat[tot.cat-i, ] == x[i, 2]] <- i
}
if (sum(sign(x[i, ])) == +2){
cluster.mat[tot.cat-i, cluster.mat[tot.cat-i, ] == x[i, 1]] <- i
cluster.mat[tot.cat-i, cluster.mat[tot.cat-i, ] == x[i, 2]] <- i
}
}
for (i in 1:nrow(cluster.mat)) list.affected.rows[[i]] <- which(cluster.mat[i, ] == (tot.cat-i))
return(list(cluster.mat, list.affected.rows))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.