spearman: Spearman's correlation coefficient

View source: R/metrics.R

spearmanR Documentation

Spearman's correlation coefficient

Description

Computes the Spearman's correlation.

Usage

spearman(x, y = x, remove_na = TRUE)

Arguments

x

(numeric | matrix) The values to calculate the correlation.

y

(numeric | matrix) The values to calculate the correlation with. the same values as x by default.

remove_na

(logical(1)) Should NA values be removed?. TRUE by default.

Details

Spearman's correlation coefficient is computed as:

cov(rank(x), rank(y)) / (sd(rank(x)) * sd(rank(y)))

where R is the rank of a variable, cov the covariance of two variables and sigma is the standard deviation.

Value

A single numeric value with the Spearman's correlation.

See Also

Other numeric_metrics: maape(), mae(), mse(), nrmse(), numeric_summary(), pearson(), r2(), rmse()

Examples

## Not run: 
set.seed(1)
x <- rnorm(100)
spearman(x, x)
spearman(x, x + rnorm(100, 2))
spearman(x, x - 1)
spearman(x, x + 10)

## End(Not run)


brandon-mosqueda/SKM documentation built on Feb. 8, 2025, 5:24 p.m.