R/comparison_metric.R

Defines functions comparison_metric

comparison_metric <- function(df, metric = c("rmse")) {
  stopifnot(inherits(df, "data.frame"))
  stopifnot(all(c("actual", "expected", "weight") %in% colnames(df)))
  metric <- match.arg(metric)

  if(metric == "rmse") {
    df %>%
      dplyr::mutate(squared_residual = (actual - expected)^2) %>%
      dplyr::summarize(rmse = sqrt(sum(squared_residual) / dplyr::n())) %>%
      unlist(use.names = FALSE)
  }

}
realgabon/insuRglm documentation built on Jan. 2, 2023, 2:51 a.m.