# dis: Dissimilarities between row observations of a matrix and a... In mlesnoff/rnirs: Dimension reduction, Regression and Discrimination for Chemometrics

 dis R Documentation

## Dissimilarities between row observations of a matrix and a given vector

### Description

Calculation of dissimilarities between the row observations of a data set and a given vector `mu`. By default, if not specified, vector `mu` is the column means of the reference (= training) data set.

### Usage

``````
dis(Xr, Xu = NULL, mu = NULL, diss = c("euclidean", "mahalanobis", "correlation"),
sigma = NULL, weights = NULL)

``````

### Arguments

 `Xr` A `n x p` matrix or data frame of reference (= training) observations. `Xu` A `m x p` matrix or data frame of new (= test) observations (`Xu` is not used in the calculation of the median and MAD used for calculating the standardized dissimilarities; see Details). `mu` The vector of length `p` which is compared to the `n` rows of `Xr` and, if not `NULL`, to the `m` rows `Xu`. If `mu` is `NULL` (default), `mu` is set to the column means of `Xr`. `diss` The type of dissimilarities used. Possible values are "euclidean" (Euclidean distances; default), "mahalanobis" (Mahalanobis distances), or "correlation". Correlation dissimilarities are calculated by `sqrt(.5 * (1 - rho))`. `sigma` For Mahalanobis distance, the covariance matrix considered. If `NULL` (default), `sigma` is set to `cov(Xr)`. `weights` Only for Mahalanobis distance and when `sigma = NULL`. 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 list of outputs, such as:

 `dr` A data frame of the dissimilarities for Xr. `du` A data frame of the dissimilarities for Xu.

### Examples

``````
n <- 8
p <- 6
set.seed(1)
X <- matrix(rnorm(n * p, mean = 10), ncol = p, byrow = TRUE)
y1 <- 100 * rnorm(n)
y2 <- 100 * rnorm(n)
Y <- cbind(y1, y2)
set.seed(NULL)

Xr <- X[1:6, ] ; Yr <- Y[1:6, ]
Xu <- X[7:8, ] ; Yu <- Y[7:8, ]

mu <- NULL
dis(Xr, mu = mu)

dis(Xr, Xu, mu)

fm <- pls(Xr, Yr, ncomp = 3)
dis(fm\$Tr, mu = mu, diss = "mahalanobis")

fm <- pls(Xr, Yr, Xu, ncomp = 3)
dis(fm\$Tr, fm\$Tu, mu, diss = "mahalanobis")

``````

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