resemble (version 1.2.2)

corDiss: Correlation and moving correlation dissimilarity measurements (corDiss)

Description

Computes correlation and moving correlation dissimilarity matrices.

Usage

corDiss(Xr, X2 = NULL, ws = NULL, 
        center = TRUE, scaled = TRUE)

Arguments

Xr
a matrix (or data.frame) containing the (reference) data.
X2
an optional matrix (or data.frame) containing data of a second set of observations (samples).
ws
for moving correlation dissimilarity, an odd integer value which specifies the window size. If ws = NULL, then the window size will be equal to the number of variables (columns), i.e. instead moving correlation, the normal correlation will be
center
a logical indicating if the spectral data Xr (and X2 if specified) must be centered. If X2 is specified the data is scaled on the basis of $Xr \cup X2$.
scaled
a logical indicating if Xr (and X2 if specified) must be scaled. If X2 is specified the data is scaled on the basis of $Xr \cup X2$.

Value

  • a matrix of the computed dissimilarities.

Details

The correlation dissimilarity $cd$ between two obsvervations $x_i$ and $x_j$ is computed as follows: $$cd(x_i, x_j) = \frac{1}{2}(1 - cor(x_i, x_j))$$ The avobe formlula is used when ws = NULL. On the other hand (when ws != NULL) the moving correlation dissimilarity $mcd$ between two obsvervations $x_i$ and $x_j$ is computed as follows: $$mcd(x_i, x_j) = \frac{1}{2 ws}\sum_{k=1}^{p-ws}(1 - cor(x_{i,(k:k+ws)}, x_{j,(k:k+ws)}))$$ where $ws$ represents a given window size which rolls sequantially fom 1 up to $p - ws$ and $p$ is the number of variables of the observations. The function does not accept input data containing missing values.

Examples

Run this code
require(prospectr)
data(NIRsoil)

Xu <- NIRsoil$spc[!as.logical(NIRsoil$train),]
Xr <- NIRsoil$spc[as.logical(NIRsoil$train),]

corDiss(Xr = Xr)

corDiss(Xr = Xr, X2 = Xu)

corDiss(Xr = Xr, ws = 41)

corDiss(Xr = Xr, X2 = Xu, ws = 41)

Run the code above in your browser using DataLab