dist: Distance Matrix for Data Sets

Description Usage Arguments Value Methods (by class) Examples

Description

This function computes and returns the distance matrix computed by using the specified distance measure to compute the pairwise distances between data points in a data set.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
dist(x, ...)

## Default S3 method:
dist(x, method = "euclidean", diag = FALSE,
  upper = FALSE, p = 2)

## S3 method for class 'sgd'
dist(x, ref_mean = 0, ref_precision = 1)

## S3 method for class 'gmd'
dist(x, rule = 2, squared = TRUE)

Arguments

x

Either a numeric matrix, a data frame, a dist object, an sgd object or a gmd object.

method

the distance measure to be used. This must be one of "euclidean", "maximum", "manhattan", "canberra", "binary" or "minkowski". Any unambiguous substring can be given.

diag

logical value indicating whether the diagonal of the distance matrix should be printed by print.dist.

upper

logical value indicating whether the upper triangle of the distance matrix should be printed by print.dist.

p

The power of the Minkowski distance.

Value

dist returns an object of class "dist".

The lower triangle of the distance matrix stored by columns in a vector, say do. If n is the number of observations, i.e., n <- attr(do, "Size"), then for i < j ≤ n, the dissimilarity between (row) i and j is do[n*(i-1) - i*(i-1)/2 + j-i]. The length of the vector is n*(n-1)/2, i.e., of order n^2.

The object has the following attributes (besides "class" equal to "dist"):

Size

integer, the number of observations in the dataset.

Labels

optionally, contains the labels, if any, of the observations of the dataset.

Diag, Upper

logicals corresponding to the arguments diag and upper above, specifying how the object should be printed.

call

optionally, the call used to create the object.

method

optionally, the distance method used; resulting from dist(), the (match.arg()ed) method argument.

Methods (by class)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
x <- sgd(
  c(mean =  0, precision = 1  ),
  c(mean =  3, precision = 0.5),
  c(mean = -1, precision = 2  )
)
dist(x)

N <- 100
M <- 4
w <- matrix(runif(N * M), N, M)
w <- w / rowSums(w)
s <- tidyr::crossing(
  observation = paste0("O", 1:N),
  component = paste0("C", 1:M)
) %>%
dplyr::mutate(mixing = as.numeric(t(w)))
d <- tibble::tibble(
  component = paste0("C", 1:M),
  mean = numeric(M),
  precision = 1:M
)
y <- gmd(s, d)
dist(y)

astamm/game documentation built on June 5, 2019, 8:53 a.m.