Skip to content

Instantly share code, notes, and snippets.

Last active Nov 20, 2022
What would you like to do?
Calculate residuals
Calc_residuals <- function(original, predicted, digits=4){
d0 <- original - predicted
d1 <- mean((d0)^2)
d2 <- mean(abs(d0))
d3 <- sqrt(mean((d0)^2))
d4a <- abs((d0/original))
d4b <- mean(d4a[!is.infinite(d4a)])*100
d5 <- round(1-(sum((d0)^2)/sum((original-mean(original))^2)), digits)
return(data.frame(mse=round(d1, digits=digits),
mae=round(d2, digits=digits),
rmse=round(d3, digits=digits),
MAPE=round(d4b, digits=digits),
R2=round(d5, digits=digits),
row.names = 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment