\HeaderA{cophenetic}{Cophenetic Distances for a Hierarchical Clustering}{cophenetic}
\methaliasA{cophenetic.default}{cophenetic}{cophenetic.default}
\methaliasA{cophenetic.dendrogram}{cophenetic}{cophenetic.dendrogram}
\keyword{cluster}{cophenetic}
\keyword{multivariate}{cophenetic}
\begin{Description}\relax
Computes the cophenetic distances for a hierarchical clustering.
\end{Description}
\begin{Usage}
\begin{verbatim}
cophenetic(x)
## Default S3 method:
cophenetic(x)
## S3 method for class 'dendrogram':
cophenetic(x)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] an R object representing a hierarchical clustering.
For the default method, an object of class \code{\LinkA{hclust}{hclust}} or
with a method for \code{\LinkA{as.hclust}{as.hclust}()} such as
\code{\LinkA{agnes}{agnes}}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The cophenetic distance between two observations that have been
clustered is defined to be the intergroup dissimilarity at which the
two observations are first combined into a single cluster.
Note that this distance has many ties and restrictions.

It can be argued that a dendrogram is an appropriate summary of some
data if the correlation between the original distances and the
cophenetic distances is high.  Otherwise, it should simply be viewed as
the description of the output of the clustering algorithm.

\code{cophenetic} is a generic function.  Support for classes which
represent hierarchical clusterings (total indexed hierarchies) can be
added by providing an \code{\LinkA{as.hclust}{as.hclust}()} or, more directly, a
\code{cophenetic()} method for such a class.

The method for objects of class \code{"\LinkA{dendrogram}{dendrogram}"} requires
that all leaves of the dendrogram object have non-null labels.
\end{Details}
\begin{Value}
An object of class \code{dist}.
\end{Value}
\begin{Author}\relax
Robert Gentleman
\end{Author}
\begin{References}\relax
Sneath, P.H.A. and Sokal, R.R. (1973)
\emph{Numerical Taxonomy: The Principles and Practice of Numerical
Classification}, p. 278 ff;
Freeman, San Francisco.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{dist}{dist}},
\code{\LinkA{hclust}{hclust}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
d1 <- dist(USArrests)
hc <- hclust(d1, "ave")
d2 <- cophenetic(hc)
cor(d1,d2) # 0.7659

## Example from Sneath & Sokal, Fig. 5-29, p.279
d0 <- c(1,3.8,4.4,5.1, 4,4.2,5, 2.6,5.3, 5.4)
attributes(d0) <- list(Size = 5, diag=TRUE)
class(d0) <- "dist"
names(d0) <- letters[1:5]
d0
str(upgma <- hclust(d0, method = "average"))
plot(upgma, hang = -1)
#
(d.coph <- cophenetic(upgma))
cor(d0, d.coph) # 0.9911
\end{ExampleCode}
\end{Examples}

