dend_expend {dendextend} | R Documentation |
Finds a "good" dendrogram for a dist
Description
There are many options for choosing distance and linkage functions for hclust. This function goes through various combinations of the two and helps find the one that is most "similar" to the original distance matrix.
Usage
dend_expend(
x,
dist_methods = c("euclidean", "maximum", "manhattan", "canberra", "binary",
"minkowski"),
hclust_methods = c("ward.D", "ward.D2", "single", "complete", "average", "mcquitty",
"median", "centroid"),
hclust_fun = hclust,
optim_fun = cor_cophenetic,
...
)
find_dend(x, ...)
Arguments
x |
A matrix or a data.frame. Can also be a dist object. |
dist_methods |
A vector of possible dist methods. |
hclust_methods |
A vector of possible hclust methods. |
hclust_fun |
By default hclust. |
optim_fun |
A function that accepts a dend and a dist and returns how the two are in agreement. Default is cor_cophenetic. |
... |
options passed from find_dend to dend_expend. |
Value
dend_expend: A list with three items. The first item is called "dends" and includes a dendlist with all the possible dendrogram combinations. The second is "dists" and includes a list with all the possible distance matrix combination. The third. "performance", is data.frame with three columns: dist_methods, hclust_methods, and optim. optim is calculated (by default) as the cophenetic correlation (see: cor_cophenetic) between the distance matrix and the cophenetic distance of the hclust object.
find_dend: A dendrogram which is "optimal" based on the output from dend_expend.
Examples
x <- datasets::mtcars
out <- dend_expend(x, dist_methods = c("euclidean", "manhattan"))
out$performance
dend_expend(dist(x))$performance
best_dend <- find_dend(x, dist_methods = c("euclidean", "manhattan"))
plot(best_dend)