calculate_rmse {trendeval}R Documentation

Generic for calculating the root mean squared error

Description

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

Usage

calculate_rmse(x, ...)

## Default S3 method:
calculate_rmse(x, ...)

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

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

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

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

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

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

## S3 method for class '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.

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.

Value

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

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.

Author(s)

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)


[Package trendeval version 0.1.0 Index]