silhouetteMLB: Run a Silhouette Analysis Similar to Matlab

Usage Arguments Examples

Usage

1
silhouetteMLB(data, fac, method = "cosine", plot = TRUE)

Arguments

data
fac
method
plot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (data, fac, method = "cosine", plot = TRUE) 
{
    if (nrow(data) != length(fac)) 
        stop("Bad input!")
    dist.matrix <- as.matrix(proxy::dist(x = data, method = method))
    sil.check <- cluster::silhouette(x = as.numeric(as.factor(fac)), 
        dist = dist.matrix)
    if (plot == TRUE) {
        tmp <- lapply(unique(sil.check[, 1]), (function(clid) {
            part.out <- sil.check[sil.check[, 1] == clid, ]
            part.out[order(part.out[, 3], decreasing = TRUE), 
                ]
        }))
        tmp <- do.call(rbind, tmp)
        xrange <- c(min(tmp[, 3]), max(tmp[, 3]))
        xrange[1] <- ifelse(xrange[1] > 0, 0, (-1.15) * abs(xrange[1]))
        xrange[2] <- 1.15
        graphics::barplot(tmp[nrow(tmp):1, 3], col = as.factor(tmp[nrow(tmp):1, 
            1]), xlim = xrange, horiz = TRUE, xlab = "Silhouette Value", 
            ylab = "", main = "Silhouette Plot", border = as.factor(tmp[nrow(tmp):1, 
                1]))
        graphics::abline(v = 0)
        graphics::title(ylab = "Iter. Results (by Group)", line = 1, 
            cex.lab = 1, font = 2)
    }
    return(as.vector(sil.check[, 3]))
  }

dami82/mutSignatures_dev documentation built on May 17, 2019, 7:02 p.m.