Learn R Programming

resemble (version 2.2.3)

cor_diss: Correlation and moving correlation dissimilarity measurements (cor_diss)

Description

Stable lifecycle

Computes correlation and moving correlation dissimilarity matrices.

Usage

cor_diss(Xr, Xu = NULL, ws = NULL,
         center = TRUE, scale = FALSE)

Value

a matrix of the computed dissimilarities.

Arguments

Xr

a matrix.

Xu

an optional matrix containing data of a second set of observations.

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 used. See details.

center

a logical indicating if the spectral data Xr (and Xu if specified) must be centered. If Xu is provided, the data is scaled on the basis of Xr XuXr U Xu.

scale

a logical indicating if Xr (and Xu if specified) must be scaled. If Xu is provided the data is scaled on the basis of Xr XuXr U Xu.

Author

Antoine Stevens and Leonardo Ramirez-Lopez

Details

The correlation dissimilarity dd between two observations x_ix_i and x_jx_j is based on the Perason's correlation coefficient () and it can be computed as follows:

d(x_i, x_j) = 12((1 - (x_i, x_j)))d(x_i, x_j) = 1/2 (1 - (x_i, x_j))

The above formula is used when ws = NULL. On the other hand (when ws != NULL) the moving correlation dissimilarity between two observations x_ix_i and x_jx_j is computed as follows:

d(x_i, x_j; ws) = 12 ws_k=1^p-ws1 - (x_i,(k:k+ws), x_j,(k:k+ws))d(x_i, x_j) = 1/(2 ws)_(k=1)^p-ws(1 - (x_(i,k:k+ws), x_(j,k:k+ws)))

where wsws represents a given window size which rolls sequentially from 1 up to p - wsp - ws and pp is the number of variables of the observations.

The function does not accept input data containing missing values.

Examples

Run this code
# \donttest{
library(prospectr)
data(NIRsoil)

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

cor_diss(Xr = Xr)

cor_diss(Xr = Xr, Xu = Xu)

cor_diss(Xr = Xr, ws = 41)

cor_diss(Xr = Xr, Xu = Xu, ws = 41)
# }

Run the code above in your browser using DataLab