cdm {multivariance} | R Documentation |
computes a doubly centered distance matrix
Description
computes the doubly centered distance matrix
Usage
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 |
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 |
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
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))