I am working on a data.frame
with both categorical and metric variables
# example data
a <- as.factor(c("A","A","B","C","D","A","C","A","C","C"))
b <- rep(1:5,2)
c <- as.factor(c("elephant","elephant","cat","dog","cat","elephant",
"cat","elephant","dog","dog"))
df <- data.frame(a,b,c)
I run a cluster analysis on this example data
# Dissimilarity Matrix Calculation
library(cluster)
x <- daisy(df, metric = c("gower"),
stand = FALSE, type = list())
# Hierarchical Clustering
z <- agnes(x, diss = inherits(x, "dist"), metric = "euclidean",
stand = FALSE, method = "single", par.method,
trace.lev = 0, keep.diss = TRUE)
and receive this dendrogram
plot(z, main="plotit", which.plot = 2)
- How do I know where to cut the tree?
I could do something like
cutree(z, k = 2, h=0.3)
but the values chosen for k
and h
would be entirely arbitrary. I work on a large data set where I can't rely on information I see in the plot in this example?
- Is there a heuristic to determine the number of clusters?
- Is there a heuristic to determine the cutting height of the tree?