Skip to contents

Computes the Adjusted Rand Index (ARI) between two cluster assignment vectors. The ARI measures the similarity between two partitions, corrected for chance. It equals 1 for identical partitions and has an expected value of 0 for independent (random) partitions.

Usage

ARI(cl1, cl2)

Arguments

cl1

Integer (or factor) vector of length \(n\) giving the first cluster assignment.

cl2

Integer (or factor) vector of length \(n\) giving the second cluster assignment.

Value

A numeric scalar in \((-1, 1]\) giving the Adjusted Rand Index.

See also

Examples

# Perfect agreement
cl1 <- c(1, 1, 2, 2, 3, 3)
cl2 <- c(2, 2, 1, 1, 3, 3)  # same partition, different labels
ARI(cl1, cl2)  # should be 1
#> [1] 1

# Random agreement
set.seed(1)
cl1 <- sample(1:3, 100, replace = TRUE)
cl2 <- sample(1:3, 100, replace = TRUE)
ARI(cl1, cl2)  # close to 0
#> [1] -0.01201092