pearson: Pearson's correlation coefficient

View source: R/metrics.R

pearsonR Documentation

Pearson's correlation coefficient

Description

Computes the Pearson's correlation.

Usage

pearson(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

Pearson's correlation coefficient is computed as:

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

where cov is the covariance of two variables and sigma is the standard deviation.

Value

A single numeric value with the Pearson's correlation.

See Also

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

Examples

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

## End(Not run)


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