corCosine: cosine correlation

Description Usage Arguments Details Value Note References See Also Examples

View source: R/corCosine.R

Description

Calculates the cosine correlation(s) between two vectors or conformable matrices.

Usage

1
corCosine(x, y)

Arguments

x

a numeric vector or matrix.

y

a vector or matrix with compatible dimensions to x.

Details

For two vectors, X and Y, the cosine similarity is defined as

similarity=cos(θ)=(∑ XY) \div (√(∑ X^2)\times √(∑ Y^2))

. For centered data the cosine and Pearson's correlation coefficients are equivalent.

Value

a numeric matrix of cosine correlations.

Note

References

van Dongen S, Enright AJ. Metric distances derived from cosine similarity and Pearson and Spearman correlations. arXiv:1208.3145 [cs, stat] [Internet]. 2012 [cited 2016 Apr 22]; http://arxiv.org/abs/1208.3145

See Also

ntp

Examples

1
2
3
4
5
6
x <- stats::rnorm(1000, mean=0, sd=1)
y <- rbinom(1000, 1, 0.25)
corCosine(10*x, -x) # equals -1
corCosine(x, x)  # equals 1
replicate(10, corCosine(x, sample(x))) # expectation 0
hist(replicate(1000, corCosine(y, sample(x)))) # expectation 0

peterawe/CMScaller documentation built on June 13, 2020, 4:49 a.m.