efronRSquared function

Efron's pseudo r-squared

Efron's pseudo r-squared

Produces Efron's pseudo r-squared from certain models, or vectors of residuals, predicted values, and actual values. Alternately produces minimum maximum accuracy, mean absolute percent error, root mean square error, or coefficient of variation.

efronRSquared( model = NULL, actual = NULL, predicted = NULL, residual = NULL, statistic = "EfronRSquared", plotit = FALSE, digits = 3, ... )

Arguments

  • model: A model of the class lm, glm, nls, betareg, gls, lme, lmerMod, lmerModLmerTest, glmmTMB, rq, loess, gam, negbin, glmRob, rlm, or mblm.
  • actual: A vector of actual y values
  • predicted: A vector of predicted values
  • residual: A vector of residuals
  • statistic: The statistic to produce. One of "EfronRSquared", "MinMaxAccuracy", "MAE", "MAPE", "MSE", "RMSE", "NRMSE.Mean", "CV".
  • plotit: If TRUE, produces plots of the predicted values vs. the actual values.
  • digits: The number of significant digits in the output.
  • ...: Other arguments passed to plot.

Returns

A single statistic

Details

Efron's pseudo r-squared is calculated as 1 minus the residual sum of squares divided by the total sum of squares. For linear models (lm model objects), Efron's pseudo r-squared will be equal to r-squared.

This function produces the same statistics as does the accuracy function. While the accuracy function extracts values from a model object, this function allows for the manual entry of residual, predicted, or actual values.

It is recommended that the user consults the accuracy

function for further details on these statistics, such as if the reported value is presented as a percentage or fraction.

If modelis not supplied, two of the following need to passed to the function: actual, predicted, residual.

Note that, for some model objects, to extract residuals and predicted values on the original scale, a type="response"

option needs to be added to the call, e.g. residuals(model.object, type="response").

Examples

data(BrendonSmall) BrendonSmall$Calories = as.numeric(BrendonSmall$Calories) BrendonSmall$Calories2 = BrendonSmall$Calories ^ 2 model.1 = lm(Sodium ~ Calories + Calories2, data = BrendonSmall) efronRSquared(model.1) efronRSquared(model.1, statistic="MAPE") efronRSquared(actual=BrendonSmall$Sodium, residual=model.1$residuals) efronRSquared(residual=model.1$residuals, predicted=model.1$fitted.values) efronRSquared(actual=BrendonSmall$Sodium, predicted=model.1$fitted.values) summary(model.1)$r.squared

References

https://rcompanion.org/handbook/F_16.html

See Also

accuracy, nagelkerke

Author(s)

Salvatore Mangiafico, mangiafico@njaes.rutgers.edu