cdm: computes a doubly centered distance matrix

Description Usage Arguments Details References Examples

View source: R/multivariance-functions.R

Description

computes the doubly centered distance matrix

Usage

1
2
3
4
5
6
7
8
cdm(
  x,
  normalize = TRUE,
  psi = NULL,
  p = NULL,
  isotropic = FALSE,
  external.dm.fun = NULL
)

Arguments

x

matrix, each row of the matrix is treated as one sample

normalize

logical, indicates if the matrix should be normalized

psi

if it is NULL, the euclidean distance will be used. In the case of isotropic = TRUE: a real valued negative definite function of one variable (accepting vectors as arguments; returning a vector of the same length). In the case of isotropic = FALSE: a real valued function of two variables (or vectors) to compute the distance of two samples based on a continuous negative definite function.

p

numeric, if it is a value between 1 and 2 then the Minkowski distance with parameter p is used.

isotropic

logical, indicates if psi of the Euclidean distance matrix should be computed, i.e., if an isotropic distance should be used.

external.dm.fun

here one can supply an external function, which computes the distance matrix given x.

Details

The doubly centered distance matrices are required for the computation of (total / m-) multivariance.

If normalize = TRUE then the value of multivariance is comparable and meaningful. It can be compared to the rejection.level or its p-value multivariance.pvalue can be computed.

More details: If normalize = TRUE the matrix is scaled such that the multivariance based on it, times the sample size, has in the limit - in the case of independence - the distribution of an L^2 norm of a Gaussian process with known expectation.

As default the Euclidean distance is used. The parameters psi, p, isotropic and external.dm.fun can be used to select a different distance. In particular, external.dm.fun can be used to provide any function which calculates a distance matrix for the rows of a given matrix.

References

For the theoretic background see the references given on the main help page of this package: multivariance-package.

Examples

1
2
3
4
5
6
7
8
9
x = coins(100)
cdm(x) # fast euclidean distances
cdm(x,psi = function(x,y) sqrt(sum((x-y)^2))) # this is identical to the previous (but slower)

# the function cdm does the following three lines in a faster way
N = nrow(x)
C = diag(N) - matrix(1/N,nrow = N,ncol = N)
A = - C %*% as.matrix(stats::dist(x,method="euclidean")) %*% C #'
all(abs(A- cdm(x,normalize = FALSE)) < 10^(-12))

multivariance documentation built on Oct. 6, 2021, 5:08 p.m.