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, (a)symmetric
binary) even when different types occur in the same dataset. Note that setting the type to symm
(symmetric binary) gives the
same dissimilarities as using nominal (which is chosen for
non-ordered factors) only when no missing values are present, and more
efficiently.
Note that daisy
now gives a warning when 2-valued numerical
variables don't have an explicit type
specified, because the
reference authors recommend to consider using "asymm"
.
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,
- 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.
- 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.
Ifnok
is the number of nonzero weights, the dissimilarity is
multiplied by the factor1/nok
and thus ranges between 0 and 1.
Ifnok = 0
, the dissimilarity is set toNA
.