
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.
r_squared(actual, predicted, w = NULL, deviance_function = mse, ...)
Observed values.
Predicted values.
Optional case weights.
A positive (deviance) function taking four arguments: "actual", "predicted", "w" and "...".
Further arguments passed to weighted_mean
and deviance_function
.
A numeric vector of length one.
[1] Cohen, Jacob. et al. (2002). Applied Multiple Regression/Correlation Analysis for the Behavioral Sciences (3rd ed.). Routledge. ISBN 978-0805822236.
# 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