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

calculate_rsq(x, ...)

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

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

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

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

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

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

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

# S3 method for trending_prediction
calculate_rsq(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::rsq_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: "rsq"

  • result: the resulting rsq 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::rsq_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_rsq(poisson_model, dat) calculate_rsq(fitted_model) calculate_rsq(fitted_model, as_tibble = TRUE) calculate_rsq(fitted_models)