Correlation-based distance can be computed using the as.dist()
function,
which converts an arbitrary square symmetric matrix into a form that
the hclust()
function recognizes as a distance matrix. However, this only
makes sense for data with at least three features since the absolute correlation
between any two observations with measurements on two features is
always 1. Hence, we will cluster a three-dimensional data set.
x <- matrix(rnorm(30 * 3), ncol = 3)
dd <- as.dist(1 - cor(t(x)))
plot(hclust(dd, method = "complete"), main = "Complete Linkage with Correlation-Based Distance", xlab = "", sub = "")
x
and store the distance matrix in dd
.hc.average
.