16.5 Distance Function


y = 37554 distance (x, metric)
computes the distance between $ p$-dimensional data points in x depending on a specified metric

The  function 37557 distance evaluates the distance between two $ p$-dimensional vectors with respect to a specified metric. The possible metrics are given in the following table:

Distance XploRe Name
$ L_1$ "l1"
$ L_2$ "l2", "euclid"
Maximum "maximum"
Cosine "cosine"
$ \chi^2$ "chisquare"
Centroid "centroid"
Tanimoto "tanimoto"
Matching "matching"
   
Several of these distances (such as Tanimoto and Matching) are designed for binary data.

The first argument of 37560 distance is the matrix, the second argument the XploRe name. By default the second argument is "l2". The commands

  x = #(1, 4)~#(1, 5)
  distance(x,"l1")
define the matrix x and evaluate the $ L_1$ distance between the rows of that matrix:
  Contents of distance
  [1,]  0.000000  7.000000
  [2,]  7.000000  0.000000
while the command
  distance(x)
yields the $ L_2$ distance, since the second argument of the function 37567 distance is missing:
  Contents of distance
  [1,]  0.000000  5.000000
  [2,]  5.000000  0.000000
The examples for this section are collected in 37570 XLGmatrix07.xpl .