computeGap: Gap computation

Description Usage Arguments Details Value Examples

View source: R/codeSpectral.R

Description

Estimate the number of clusters thanks to the gap computation.

Usage

1
computeGap(sim, Kmax)

Arguments

sim

similarity matrix.

Kmax

maximal number of clusters.

Details

computeGap returns an estimated number of clusters

Value

The function returns a list containing:

val

vector containing the eigenvalues of the similarity matrix.

gap

vector containing gap values between two successive eigenvalues.

Kmax

estimated number of clusters.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
dat <- rbind(matrix(rnorm(100, mean = 0, sd = 0.3), ncol = 2), 
           matrix(rnorm(100, mean = 2, sd = 0.3), ncol = 2), 
           matrix(rnorm(100, mean = 4, sd = 0.3), ncol = 2))

sim <- computeGaussianSimilarity(dat, 1)
res <- computeGap(sim, Kmax = 20)

plot(res$val[1:20], type = "o", ann = FALSE, axes = FALSE)
abline(v = res$Kmax, col = "darkred")
abline(h = res$val[res$Kmax], col = "darkred")
axis(side = 1, at = c(seq(0,20,by=5), res$Kmax), 
     labels = c(seq(0,20,by=5), res$Kmax), cex.axis = .7)
axis(side = 2)
title("Automatic estimation of number of clusters - Gap method")
mtext("Number of clusters", side = 1, line = 3)
mtext("Eigenvalue", side = 2, line = 3)
box()

RclusTool documentation built on Feb. 4, 2020, 5:08 p.m.