Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

r_squared

Pseudo R-Squared


Description

Returns (weighted) proportion of deviance explained, see reference below. For the mean-squared error as deviance, this equals the usual (weighted) R-squared. The higher, the better.

Usage

r_squared(actual, predicted, w = NULL, deviance_function = mse, ...)

Arguments

actual

Observed values.

predicted

Predicted values.

w

Optional case weights.

deviance_function

A positive (deviance) function taking four arguments: "actual", "predicted", "w" and "...".

...

Further arguments passed to weighted_mean and deviance_function.

Details

For simplicity, the deviance gain is calculated regarding the null model derived from the actual values.

Value

A numeric vector of length one.

References

Cohen, Jacob. et al. (2002). Applied Multiple Regression/Correlation Analysis for the Behavioral Sciences (3rd ed.). Routledge. ISBN 978-0805822236.

See Also

Examples

r_squared(1:10, c(1, 1:9))
r_squared(1:10, c(1, 1:9), w = rep(1, 10))
r_squared(1:10, c(1, 1:9), w = 1:10)
r_squared(1:10, c(1, 1:9), deviance_function = deviance_normal)
r_squared(0:2, c(0.1, 1, 2), deviance_function = deviance_poisson)
r_squared(0:2, c(0.1, 1, 2), w = rep(1, 3), deviance_function = deviance_poisson)
r_squared(0:2, c(0.1, 1, 2), deviance_function = deviance_tweedie, tweedie_p = 1)
r_squared(0:2, c(0.1, 1, 2), w = rep(1, 3),
  deviance_function = deviance_tweedie, tweedie_p = 1)

# respect to own deviance formula
myTweedie <- function(actual, predicted, w = NULL, ...) {
  deviance_tweedie(actual, predicted, w, tweedie_p = 1.5, ...)
}
r_squared(1:10, c(1, 1:9), deviance_function = myTweedie)

MetricsWeighted

Weighted Metrics, Scoring Functions and Performance Measures for Machine Learning

v0.5.2
GPL (>= 2)
Authors
Michael Mayer [aut, cre, cph], Christian Lorentzen [ctb, rev]
Initial release
2021-04-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.