# matdis: Dissimilarity matrix (between observations) In mlesnoff/rnirs: Dimension reduction, Regression and Discrimination for Chemometrics

 matdis R Documentation

## Dissimilarity matrix (between observations)

### Description

Calculation of a dissimilarity matrix for a data set: dissimilarities calculated between each of the row observations of the data set.

### Usage

``matdis(X, diss = c("euclidean", "mahalanobis", "correlation"), weights = NULL)``

### Arguments

 `X` A `n x p` matrix or data frame. `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 `n` defining a priori weights to apply to the training observations, for the computation of the covariance matrix. Internally, weights are "normalized" to sum to 1. Default to `NULL` (weights are set to `1 / n`).

### Value

A `n x n` distance matrix.

### Examples

``````
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)))

``````

mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.