Skip to contents

Creates a configuration object for computing cosine dissimilarity (also known as spectral angle mapper). Pass the result to dissimilarity() to compute the dissimilarity matrix.

The cosine dissimilarity between two observations \(x_i\) and \(x_j\) is:

\[c(x_i, x_j) = \cos^{-1} \frac{\sum_{k=1}^{p} x_{i,k}\, x_{j,k}} {\sqrt{\sum_{k=1}^{p} x_{i,k}^{2}}\, \sqrt{\sum_{k=1}^{p} x_{j,k}^{2}}}\]

where \(p\) is the number of variables.

Usage

diss_cosine(center = TRUE, scale = FALSE)

Arguments

center

Logical. Center the data before computing dissimilarities? Applied jointly to Xr and Xu if both are provided. Default TRUE.

scale

Logical. Scale the data before computing dissimilarities? Applied jointly to Xr and Xu if both are provided. Default FALSE.

Value

An object of class c("diss_cosine", "diss_method").

Examples

m <- diss_cosine()
m <- diss_cosine(center = FALSE)