Skip to contents

Measure to compare true observed response with predicted response in regression tasks.

Usage

rsq(truth, response, na_value = NaN, ...)

Arguments

truth

(numeric())
True (observed) values. Must have the same length as response.

response

(numeric())
Predicted response values. Must have the same length as truth.

na_value

(numeric(1))
Value that should be returned if the measure is not defined for the input (as described in the note). Default is NaN.

...

(any)
Additional arguments. Currently ignored.

Value

Performance value as numeric(1).

Details

R Squared is defined as $$ 1 - \frac{\sum_{i=1}^n \left( t_i - r_i \right)^2}{\sum_{i=1}^n \left( t_i - \bar{t} \right)^2}, $$ where \(\bar{t} = \sum_{i=1}^n t_i\).

Also known as coefficient of determination or explained variation. Subtracts the rse() from 1, hence it compares the squared error of the predictions relative to a naive model predicting the mean.

This measure is undefined for constant \(t\).

Meta Information

  • Type: "regr"

  • Range: \((-\infty, 1]\)

  • Minimize: FALSE

  • Required prediction: response

See also

Other Regression Measures: ae(), ape(), bias(), ktau(), linex(), mae(), mape(), maxae(), maxse(), medae(), medse(), mse(), msle(), pbias(), pinball(), rae(), rmse(), rmsle(), rrse(), rse(), sae(), se(), sle(), smape(), srho(), sse()

Examples

set.seed(1)
truth = 1:10
response = truth + rnorm(10)
rsq(truth, response)
#> [1] 0.9314108