Generic calculate_rmse() returns the root mean square error for the given input.

calculate_rmse(x, ...)

# S3 method for default
calculate_rmse(x, ...)

# S3 method for trending_model
calculate_rmse(x, data, na.rm = TRUE, as_tibble = TRUE, ...)

# S3 method for list
calculate_rmse(x, data, na.rm = TRUE, ...)

# S3 method for trending_fit
calculate_rmse(x, new_data, na.rm = TRUE, as_tibble = TRUE, ...)

# S3 method for trending_fit_tbl
calculate_rmse(x, new_data, na.rm = TRUE, ...)

# S3 method for trending_predict
calculate_rmse(x, na.rm = TRUE, as_tibble = TRUE, ...)

# S3 method for trending_predict_tbl
calculate_rmse(x, na.rm = TRUE, ...)

# S3 method for trending_prediction
calculate_rmse(x, na.rm = TRUE, as_tibble = TRUE, ...)

Arguments

x

An R object.

...

Not currently used.

data

a data.frame containing data (including the response variable and all predictors) used in the specified model.

na.rm

Should NA values should be removed before calculation of metric (passed to the underlying function yardstick::rmse_vec).

as_tibble

Should the result be returned as tibble (as_tibble = TRUE) or a list (as_tibble = FALSE).

new_data

a data.frame containing data (including the response variable and all predictors) on which to assess the model.

Value

For a single trending_fit input, if as_tibble = FALSE the object returned will be a list with entries:

  • metric: "rmse"

  • result: the resulting rmse value (NULL if the calculation failed)

  • warnings: any warnings generated during calculation

  • errors: any errors generated during calculation

If as_tibble = TRUE, or for the other trending classes, then the output will be a tibble with one row for each fitted model columns corresponding to output generated with single model input.

Details

Specific methods are given for trending_model (and lists of these), trending_fit, trending_fit_tbl, trending_predict_tbl, trending_predict_tbl and trending_prediction objects. Each of these are simply wrappers around the yardstick::rmse_vec with the addition of explicit error handling.

Author

Tim Taylor

#' @examples x = rnorm(100, mean = 0) y = rpois(n = 100, lambda = exp(1.5 + 0.5*x)) dat <- data.frame(x = x, y = y) poisson_model <- glm_model(y ~ x , family = "poisson") negbin_model <- glm_nb_model(y ~ x) fitted_model <- fit(poisson_model, dat) fitted_models <- fit(list(poisson_model, negbin_model), data = dat)

calculate_rmse(poisson_model, dat) calculate_rmse(fitted_model) calculate_rmse(fitted_model, as_tibble = TRUE) calculate_rmse(fitted_models)