# compare.rand: (+) Rand Index In T4cluster: Tools for Cluster Analysis

## Description

Compute Rand index between two clusterings. It has a value between 0 and 1 where 0 indicates two clusterings do not agree and 1 exactly the same.

## Usage

 `1` ```compare.rand(x, y) ```

## Arguments

 `x` 1st cluster label vector of length-n. `y` 2nd cluster label vector of length-n.

## Value

Rand Index value.

## References

\insertRef

rand_objective_1971T4cluster

## 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``` ```# ------------------------------------------------------------- # true label vs. clustering with 'iris' dataset # ------------------------------------------------------------- ## PREPARE data(iris) X = as.matrix(iris[,1:4]) lab = as.integer(as.factor(iris[,5])) ## CLUSTERING WITH DIFFERENT K VALUES vec_k = 2:7 vec_cl = list() for (i in 1:length(vec_k)){ vec_cl[[i]] = T4cluster::kmeans(X, k=round(vec_k[i]))\$cluster } ## COMPUTE COMPARISON INDICES vec_comp = rep(0, length(vec_k)) for (i in 1:length(vec_k)){ vec_comp[i] = compare.rand(vec_cl[[i]], lab) } ## VISUALIZE opar <- par(no.readonly=TRUE) plot(vec_k, vec_comp, type="b", lty=2, xlab="number of clusters", ylab="comparison index", main="Rand Index with true k=3") abline(v=3, lwd=2, col="red") par(opar) ```

T4cluster documentation built on Aug. 16, 2021, 9:07 a.m.