r2: R-Squared

View source: R/metrics.R

r2R Documentation

R-Squared

Description

Computes the R-Squared.

Usage

r2(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:

Cor(x, y)^2

where Cor is the Pearson's correlation coefficient of the two variables.

Value

A single numeric value with the R-Squared value.

See Also

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

Examples

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

## End(Not run)


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