matdis | R Documentation |
Calculation of a dissimilarity matrix for a data set: dissimilarities calculated between each of the row observations of the data set.
matdis(X, diss = c("euclidean", "mahalanobis", "correlation"), weights = NULL)
X |
A |
diss |
Type of dissimilarities calculated. Possible values are "euclidean" (default; Euclidean distance), "mahalanobis" (Mahalanobis distance), or "correlation". Correlation dissimilarities are calculated by sqrt(.5 * (1 - rho)). |
weights |
Only for Mahalanobis distance. A vector of length |
A n x n
distance matrix.
n <- 8
p <- 6
set.seed(1)
X <- matrix(rnorm(n * p, mean = 10), ncol = p, byrow = TRUE)
set.seed(NULL)
X
matdis(X)
i <- 2 ; j <- 3
sqrt(sum((X[i, ] - X[j, ])^2))
matdis(X, diss = "mahalanobis")
i <- 2
sqrt(mahalanobis(X, center = X[i, ], cov = cov(X)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.