#' Bias
#'
#' \code{bias} computes r-squared (r2), bias and root mean square error (RMSE) given a vector of observation and prediction.
#' @param obs vector of observation.
#' @param pred vector of prediction.
#'
#' @return A data.frame containing r2, bias and RMSE.
#' @export
#'
#' @examples
#' bias(1:10, 1:10 + rnorm(10))
bias = function(obs, pred) {
n = length(obs) # sample size
ssr = sum((obs - pred) ^ 2) # sum of squared residuals
r2 = 1 - ssr / sum((obs - mean(obs)) ^ 2) # r2
bias = mean(pred - obs) # bias
rmse = sqrt(ssr / n) # RMSE
return(
data.frame(
'R2' = r2,
'BIAS' = bias,
'RMSE' = rmse
)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.