daisy {cluster}  R Documentation 
Compute all the pairwise dissimilarities (distances) between observations in the dataset. The original variables may be of mixed types.
daisy(x, metric = c("euclidean","manhattan"), stand = FALSE, type = list())
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, columns of class factor will be
recognized as nominal variables, and columns of class ordered
will be recognized as ordinal variables. Other variable types
should be specified with the type argument. Missing values
(NA s) are allowed.

metric 
character string specifying the metric to be used.
The currently available options are "euclidean" (the default)
and "manhattan" .Euclidean distances are root sumofsquares of differences, and manhattan distances are the sum of absolute differences. If not all columns of x are numeric, metric will be
ignored.

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 variable's mean absolute deviation.
If not all columns of x are numeric, stand will
be ignored and Gower's standardization (based on the
range ) will be applied in any case.

type 
list for specifying 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" (ratio scaled variables that
must be logarithmically transformed), "asymm" (asymmetric
binary) and "symm" (symmetric binary variables). Each
component's value is a vector, containing the names or the numbers
of the corresponding columns of x .
Variables not mentioned in the type list are interpreted as
usual (see argument x ).

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
nonordered factors) only when no missing values are present, and more
efficiently.
Note that daisy
now gives a warning when 2valued 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,
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.
If nok
is the number of nonzero weights, the dissimilarity is
multiplied by the factor 1/nok
and thus ranges between 0 and 1.
If nok = 0
, the dissimilarity is set to NA
.
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.
Dissimilarities are used as inputs to cluster analysis and multidimensional scaling. The choice of metric may have a large impact.
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 SPLUS, Computational Statistics and Data Analysis, 26, 1737.
dissimilarity.object
, dist
,
pam
, fanny
, clara
,
agnes
, diana
.
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))) ## this failed earlier: summary(dfl3 < daisy(flower, type = list(asymm = c("V1", "V3"), symm= 2, ordratio= 7, logratio= 8)))