MetricsWeighted (version 0.3.0)

r_squared: Pseudo R-Squared

Description

Returns (weighted) proportion of deviance explained, see e.g. [1]. 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.

Value

A numeric vector of length one.

References

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

See Also

deviance_normal, mse.

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab