daisy

0th

Percentile

Dissimilarity Matrix Calculation

Compute all the pairwise dissimilarities (distances) between observations in the dataset. The original variables may be of mixed types.

Keywords
cluster
Usage
daisy(x, metric = "euclidean", stand = FALSE, type = list())
Arguments
x
numeric matrix or data frame. Dissimilarities will be computed between the rows of x. Columns of mode numeric (i.e. all columns when x is a matrix) will be recognized as interval scaled variables, colum
metric
character string specifying the metric to be used. The currently available options are "euclidean" (the default) and "manhattan". Euclidean distances are root sum-of-squares of differences, and manhattan distances are
stand
logical flag: if TRUE, then the measurements in x are standardized before calculating the dissimilarities. Measurements are standardized for each variable (column), by subtracting the variable's mean value and dividing by the
type
list containing some (or all) of the types of the variables (columns) in x. The list may contain the following components: "ordratio" (ratio scaled variables to be treated as ordinal variables), "logratio"
Details

daisy is fully described in chapter 1 of Kaufman and Rousseeuw (1990). Compared to dist whose input must be numeric variables, the main feature of daisy is its ability to handle other variable types as well (e.g. nominal, ordinal, asymmetric binary) even when different types occur in the same dataset.

In the daisy algorithm, missing values in a row of x are not included in the dissimilarities involving that row. There are two main cases,

  1. If all variables are interval scaled, the metric is "euclidean", and ng is the number of columns in which neither row i and j have NAs, then the dissimilarity d(i,j) returned is sqrt(ncol(x)/ng) times the Euclidean distance between the two vectors of length ng shortened to exclude NAs. The rule is similar for the "manhattan" metric, except that the coefficient is ncol(x)/ng. If ng is zero, the dissimilarity is NA.
  2. When some variables have a type other than interval scaled, the dissimilarity between two rows is the weighted sum of the contributions of each variable. The weight becomes zero when that variable is missing in either or both rows, or when the variable is asymmetric binary and both values are zero. In all other situations, the weight of the variable is 1.

The contribution of a nominal or binary variable to the total dissimilarity is 0 if both values are different, 1 otherwise. The contribution of other variables is the absolute difference of both values, divided by the total range of that variable. Ordinal variables are first converted to ranks.

Ifnokis the number of nonzero weights, the dissimilarity is multiplied by the factor1/nokand thus ranges between 0 and 1. Ifnok = 0, the dissimilarity is set toNA.

Value

  • an object of class "dissimilarity" containing the dissimilarities among the rows of x. This is typically the input for the functions pam, fanny, agnes or diana. See dissimilarity.object for details.

BACKGROUND

Dissimilarities are used as inputs to cluster analysis and multidimensional scaling. The choice of metric may have a large impact.

References

Kaufman, L. and Rousseeuw, P.J. (1990). Finding Groups in Data: An Introduction to Cluster Analysis. Wiley, New York.

Struyf, A., Hubert, M. and Rousseeuw, P.J. (1997). Integrating Robust Clustering Techniques in S-PLUS, Computational Statistics and Data Analysis, 26, 17-37.

See Also

dissimilarity.object, dist, pam, fanny, clara, agnes, diana.

Aliases
  • daisy
Examples
data(agriculture)
## Example 1 in ref:
##  Dissimilarities using Euclidean metric and without standardization
d.agr <- daisy(agriculture, metric = "euclidean", stand = FALSE)
d.agr
as.matrix(d.agr)[,"DK"] # via as.matrix.dist(.)

data(flower)
## Example 2 in ref
summary(dfl1 <- daisy(flower, type = list(asymm = 3)))
summary(dfl2 <- daisy(flower, type = list(asymm = c(1, 3), ordratio = 7)))
Documentation reproduced from package cluster, version 1.4-1, License: GPL version 2 or later

Community examples

sergiudinu47@gmail.com at Apr 5, 2019 cluster v2.0.7-1

https://towardsdatascience.com/hierarchical-clustering-on-categorical-data-in-r-a27e578f2995 There's an articles, and author is using daisy.