diff --git a/DESCRIPTION b/DESCRIPTION index 85f666826..184e71ddc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.15.3.6 +Version: 0.15.3.7 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NEWS.md b/NEWS.md index 664270df7..8f400845b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,9 @@ `RMSR` (Root Mean Square Residual) instead of `RMSA`. The `RMSR_corrected` column (previously `RMSA_corrected`) is also renamed accordingly. +* The first argument in `check_model()`, `check_predictions()` and + `check_convergence()` was renamed to `model`. + ## Changes * `check_model()` now limits the number of data points for models with many @@ -13,7 +16,7 @@ argument. * `check_model()` can now show or hide confidence intervals using the `show_ci` - argument. For models with only categorical predictors, cnmfidence intervals + argument. For models with only categorical predictors, confidence intervals are not shown by default. ## Bug fixes diff --git a/R/check_convergence.R b/R/check_convergence.R index fa05a4623..b196c0753 100644 --- a/R/check_convergence.R +++ b/R/check_convergence.R @@ -4,9 +4,10 @@ #' @description `check_convergence()` provides an alternative convergence #' test for `merMod`-objects. #' -#' @param x A `merMod` or `glmmTMB`-object. +#' @param model A `merMod` or `glmmTMB`-object. #' @param tolerance Indicates up to which value the convergence result is #' accepted. The smaller `tolerance` is, the stricter the test will be. +#' @param x Deprecated, please use `model` instead. #' @param ... Currently not used. #' #' @return `TRUE` if convergence is fine and `FALSE` if convergence @@ -50,8 +51,16 @@ #' check_convergence(model) #' } #' @export -check_convergence <- function(x, tolerance = 0.001, ...) { - out <- .safe(insight::is_converged(x, tolerance = tolerance, ...)) +check_convergence <- function(model = NULL, tolerance = 0.001, x = NULL, ...) { + ## TODO remove deprecation warning later + if (!is.null(x) && is.null(model)) { + insight::format_warning( + "Argument `x` is deprecated; please use `model` instead." + ) + model <- x + } + .is_model_valid(model) + out <- .safe(insight::is_converged(model, tolerance = tolerance, ...)) if (is.null(out)) { insight::format_alert("Could not compute convergence information.") out <- NA diff --git a/R/check_model.R b/R/check_model.R index ddccebe23..5ff13b21a 100644 --- a/R/check_model.R +++ b/R/check_model.R @@ -9,7 +9,7 @@ #' If `check_model()` doesn't work as expected, try setting `verbose = TRUE` to #' get hints about possible problems. #' -#' @param x A model object. +#' @param model A model object. #' @param size_dot,size_line Size of line and dot-geoms. #' @param base_size,size_title,size_axis_title Base font size for axis and plot titles. #' @param panel Logical, if `TRUE`, plots are arranged as panels; else, @@ -56,6 +56,8 @@ #' @param verbose If `FALSE` (default), suppress most warning messages. #' @param ... Arguments passed down to the individual check functions, especially #' to `check_predictions()` and `binned_residuals()`. +#' @param x Deprecated, please use `model` instead. +#' #' @inheritParams check_predictions #' #' @return The data frame that is used for plotting. @@ -191,7 +193,7 @@ #' check_model(m, panel = FALSE) #' } #' @export -check_model <- function(x, ...) { +check_model <- function(model = NULL, ...) { UseMethod("check_model") } @@ -201,7 +203,7 @@ check_model <- function(x, ...) { #' @rdname check_model #' @export check_model.default <- function( - x, + model = NULL, panel = TRUE, check = "all", detrend = TRUE, @@ -221,14 +223,23 @@ check_model.default <- function( colors = c("#3aaf85", "#1b6ca8", "#cd201f"), theme = see::theme_lucid(), verbose = FALSE, + x = NULL, ... ) { + ## TODO remove deprecation warning later + if (!is.null(x) && is.null(model)) { + insight::format_warning( + "Argument `x` is deprecated; please use `model` instead." + ) + model <- x + } + # check model formula if (verbose) { - insight::formula_ok(x) + insight::formula_ok(model) } - minfo <- insight::model_info(x, verbose = FALSE) + minfo <- insight::model_info(model, verbose = FALSE) # set default for residual_type if (is.null(residual_type)) { @@ -250,10 +261,10 @@ check_model.default <- function( assumptions_data <- tryCatch( if (minfo$is_bayesian) { - suppressWarnings(.check_assumptions_stan(x, ...)) + suppressWarnings(.check_assumptions_stan(model, ...)) } else if (minfo$is_linear) { suppressWarnings(.check_assumptions_linear( - x, + model, minfo, check, residual_type, @@ -262,7 +273,7 @@ check_model.default <- function( )) } else { suppressWarnings(.check_assumptions_glm( - x, + model, minfo, check, residual_type, @@ -283,7 +294,7 @@ check_model.default <- function( paste("`check_model()` returned following error:", cleaned_string), paste0( "\nIf the error message does not help identifying your problem, another reason why `check_model()` failed might be that models of class `", - class(x)[1], + class(model)[1], "` are not yet supported." ) # nolint ) @@ -293,7 +304,7 @@ check_model.default <- function( if (is.null(assumptions_data$QQ) && residual_type == "simulated") { insight::format_alert(paste0( "Cannot simulate residuals for models of class `", - class(x)[1], + class(model)[1], "`. Please try `check_model(..., residual_type = \"normal\")` instead." )) } @@ -309,7 +320,7 @@ check_model.default <- function( } # set default for show_dots, based on "model size" - n <- .safe(insight::n_obs(x)) + n <- .safe(insight::n_obs(model)) if (is.null(show_dots)) { show_dots <- is.null(n) || n <= 1e5 } @@ -322,7 +333,7 @@ check_model.default <- function( } # if we have only categorical predictors, we don't show CI by default - parameter_types <- .safe(parameters::parameters_type(x)) + parameter_types <- .safe(parameters::parameters_type(model)) if ( !is.null(parameter_types) && all(parameter_types$Type %in% c("intercept", "factor")) ) { @@ -350,7 +361,7 @@ check_model.default <- function( attr(assumptions_data, "bandwidth") <- bandwidth attr(assumptions_data, "type") <- type attr(assumptions_data, "maximum_dots") <- maximum_dots - attr(assumptions_data, "model_class") <- class(x)[1] + attr(assumptions_data, "model_class") <- class(model)[1] assumptions_data } @@ -377,7 +388,7 @@ plot.check_model <- function(x, ...) { #' @export check_model.stanreg <- function( - x, + model = NULL, panel = TRUE, check = "all", detrend = TRUE, @@ -397,10 +408,19 @@ check_model.stanreg <- function( colors = c("#3aaf85", "#1b6ca8", "#cd201f"), theme = see::theme_lucid(), verbose = FALSE, + x = NULL, ... ) { + ## TODO remove deprecation warning later + if (!is.null(x) && is.null(model)) { + insight::format_warning( + "Argument `x` is deprecated; please use `model` instead." + ) + model <- x + } + check_model( - bayestestR::bayesian_as_frequentist(x), + model = .safe(bayestestR::bayesian_as_frequentist(model)), size_dot = size_dot, size_line = size_line, panel = panel, @@ -430,7 +450,7 @@ check_model.brmsfit <- check_model.stanreg #' @export check_model.model_fit <- function( - x, + model = NULL, panel = TRUE, check = "all", detrend = TRUE, @@ -450,10 +470,19 @@ check_model.model_fit <- function( colors = c("#3aaf85", "#1b6ca8", "#cd201f"), theme = see::theme_lucid(), verbose = FALSE, + x = NULL, ... ) { + ## TODO remove deprecation warning later + if (!is.null(x) && is.null(model)) { + insight::format_warning( + "Argument `x` is deprecated; please use `model` instead." + ) + model <- x + } + check_model( - x$fit, + model$fit, size_dot = size_dot, size_line = size_line, panel = panel, @@ -479,7 +508,7 @@ check_model.model_fit <- function( #' @export check_model.performance_simres <- function( - x, + model = NULL, panel = TRUE, check = "all", detrend = TRUE, @@ -499,10 +528,19 @@ check_model.performance_simres <- function( colors = c("#3aaf85", "#1b6ca8", "#cd201f"), theme = see::theme_lucid(), verbose = FALSE, + x = NULL, ... ) { + ## TODO remove deprecation warning later + if (!is.null(x) && is.null(model)) { + insight::format_warning( + "Argument `x` is deprecated; please use `model` instead." + ) + model <- x + } + check_model( - x$fittedModel, + model$fittedModel, size_dot = size_dot, size_line = size_line, panel = panel, diff --git a/R/check_predictions.R b/R/check_predictions.R index a61f88e49..aac99c3f3 100644 --- a/R/check_predictions.R +++ b/R/check_predictions.R @@ -14,7 +14,7 @@ #' If `check_predictions()` doesn't work as expected, try setting #' `verbose = TRUE` to get hints about possible problems. #' -#' @param object A statistical model. +#' @param model A statistical model. #' @param iterations The number of draws to simulate/bootstrap. #' @param check_range Logical, if `TRUE`, includes a plot with the minimum #' value of the original response against the minimum values of the replicated @@ -36,7 +36,10 @@ #' options are appropriate for models with discrete - binary, integer or ordinal #' etc. - outcomes). #' @param verbose Toggle warnings. -#' @param ... Passed down to `simulate()`. +#' @param ... Additional arguments passed on to downstream functions. For +#' frequentist models, these are forwarded to `simulate()`; for Bayesian models +#' (e.g., `stanreg`, `brmsfit`), they are forwarded to `bayesplot::pp_check()`. +#' @param object Deprecated, please use `model` instead. #' #' @return A data frame of simulated responses and the original response vector. #' @@ -92,34 +95,44 @@ #' check_predictions(model, type = "discrete_both") #' #' @export -check_predictions <- function(object, ...) { +check_predictions <- function(model = NULL, ...) { UseMethod("check_predictions") } #' @rdname check_predictions #' @export check_predictions.default <- function( - object, + model = NULL, iterations = 50, check_range = FALSE, re_formula = NULL, bandwidth = "nrd", type = "density", verbose = TRUE, + object = NULL, ... ) { - .is_model_valid(object) + ## TODO remove deprecation warning later + if (!is.null(object) && is.null(model)) { + insight::format_warning( + "Argument `object` is deprecated; please use `model` instead." + ) + model <- object + } + + .is_model_valid(model) + # check_predictions() can't handle exotic formula notation if (verbose) { insight::formula_ok( - object, + model, action = "error", prefix_msg = "Posterior predictive checks failed due to an incompatible model formula." # nolint ) } # retrieve model information - minfo <- insight::model_info(object, verbose = FALSE) + minfo <- insight::model_info(model, verbose = FALSE) # try to find sensible default for "type" argument suggest_dots <- (minfo$is_bernoulli || @@ -138,7 +151,7 @@ check_predictions.default <- function( ) pp_check.lm( - object, + model, iterations = iterations, check_range = check_range, re_formula = re_formula, @@ -153,17 +166,26 @@ check_predictions.default <- function( #' @export check_predictions.stanreg <- function( - object, + model = NULL, iterations = 50, check_range = FALSE, re_formula = NULL, bandwidth = "nrd", type = "density", verbose = TRUE, + object = NULL, ... ) { + ## TODO remove deprecation warning later + if (!is.null(object) && is.null(model)) { + insight::format_warning( + "Argument `object` is deprecated; please use `model` instead." + ) + model <- object + } + # retrieve model information - minfo <- insight::model_info(object, verbose = FALSE) + minfo <- insight::model_info(model, verbose = FALSE) # try to find sensible default for "type" argument suggest_dots <- (minfo$is_bernoulli || @@ -190,15 +212,15 @@ check_predictions.stanreg <- function( ) # for plotting - resp_string <- insight::find_terms(object)$response + resp_string <- insight::find_terms(model)$response - if (inherits(object, "brmsfit")) { + if (inherits(model, "brmsfit")) { out <- as.data.frame( - bayesplot::pp_check(object, type = pp_type, ndraws = iterations, ...)$data + bayesplot::pp_check(model, type = pp_type, ndraws = iterations, ...)$data ) } else { out <- as.data.frame( - bayesplot::pp_check(object, plotfun = pp_type, nreps = iterations, ...)$data + bayesplot::pp_check(model, plotfun = pp_type, nreps = iterations, ...)$data ) } @@ -247,15 +269,24 @@ check_predictions.brmsfit <- check_predictions.stanreg #' @export check_predictions.BFBayesFactor <- function( - object, + model = NULL, iterations = 50, check_range = FALSE, re_formula = NULL, bandwidth = "nrd", verbose = TRUE, + object = NULL, ... ) { - everything_we_need <- .get_bfbf_predictions(object, iterations = iterations) + ## TODO remove deprecation warning later + if (!is.null(object) && is.null(model)) { + insight::format_warning( + "Argument `object` is deprecated; please use `model` instead." + ) + model <- object + } + + everything_we_need <- .get_bfbf_predictions(model, iterations = iterations) y <- everything_we_need[["y"]] sig <- everything_we_need[["sigma"]] @@ -284,7 +315,7 @@ pp_check.BFBayesFactor <- check_predictions.BFBayesFactor #' @export -check_predictions.lme <- function(object, ...) { +check_predictions.lme <- function(model = NULL, ...) { insight::format_error( "`check_predictions()` does currently not work for models of class `lme`." ) diff --git a/man/check_convergence.Rd b/man/check_convergence.Rd index 55f363de1..08c7dc366 100644 --- a/man/check_convergence.Rd +++ b/man/check_convergence.Rd @@ -4,14 +4,16 @@ \alias{check_convergence} \title{Convergence test for mixed effects models} \usage{ -check_convergence(x, tolerance = 0.001, ...) +check_convergence(model = NULL, tolerance = 0.001, x = NULL, ...) } \arguments{ -\item{x}{A \code{merMod} or \code{glmmTMB}-object.} +\item{model}{A \code{merMod} or \code{glmmTMB}-object.} \item{tolerance}{Indicates up to which value the convergence result is accepted. The smaller \code{tolerance} is, the stricter the test will be.} +\item{x}{Deprecated, please use \code{model} instead.} + \item{...}{Currently not used.} } \value{ diff --git a/man/check_model.Rd b/man/check_model.Rd index 9dd2f5266..4c4ab1688 100644 --- a/man/check_model.Rd +++ b/man/check_model.Rd @@ -5,10 +5,10 @@ \alias{check_model.default} \title{Visual check of model assumptions} \usage{ -check_model(x, ...) +check_model(model = NULL, ...) \method{check_model}{default}( - x, + model = NULL, panel = TRUE, check = "all", detrend = TRUE, @@ -28,11 +28,12 @@ check_model(x, ...) colors = c("#3aaf85", "#1b6ca8", "#cd201f"), theme = see::theme_lucid(), verbose = FALSE, + x = NULL, ... ) } \arguments{ -\item{x}{A model object.} +\item{model}{A model object.} \item{...}{Arguments passed down to the individual check functions, especially to \code{check_predictions()} and \code{binned_residuals()}.} @@ -104,6 +105,8 @@ for dots, and third color for outliers or extreme values.} \code{theme = ggplot2::theme_dark()}.} \item{verbose}{If \code{FALSE} (default), suppress most warning messages.} + +\item{x}{Deprecated, please use \code{model} instead.} } \value{ The data frame that is used for plotting. diff --git a/man/check_predictions.Rd b/man/check_predictions.Rd index 1195927c5..cc9f0d426 100644 --- a/man/check_predictions.Rd +++ b/man/check_predictions.Rd @@ -5,23 +5,26 @@ \alias{check_predictions.default} \title{Posterior predictive checks} \usage{ -check_predictions(object, ...) +check_predictions(model = NULL, ...) \method{check_predictions}{default}( - object, + model = NULL, iterations = 50, check_range = FALSE, re_formula = NULL, bandwidth = "nrd", type = "density", verbose = TRUE, + object = NULL, ... ) } \arguments{ -\item{object}{A statistical model.} +\item{model}{A statistical model.} -\item{...}{Passed down to \code{simulate()}.} +\item{...}{Additional arguments passed on to downstream functions. For +frequentist models, these are forwarded to \code{simulate()}; for Bayesian models +(e.g., \code{stanreg}, \code{brmsfit}), they are forwarded to \code{bayesplot::pp_check()}.} \item{iterations}{The number of draws to simulate/bootstrap.} @@ -49,6 +52,8 @@ options are appropriate for models with discrete - binary, integer or ordinal etc. - outcomes).} \item{verbose}{Toggle warnings.} + +\item{object}{Deprecated, please use \code{model} instead.} } \value{ A data frame of simulated responses and the original response vector. diff --git a/tests/testthat/_snaps/check_collinearity.md b/tests/testthat/_snaps/check_collinearity.md index 2772c424a..5b76de9a3 100644 --- a/tests/testthat/_snaps/check_collinearity.md +++ b/tests/testthat/_snaps/check_collinearity.md @@ -1,17 +1,3 @@ -# check_collinearity, ci = NULL - - Code - out - Output - # Check for Multicollinearity - - Low Correlation - - Term VIF adj. VIF Tolerance - N 1 1 1 - P 1 1 1 - K 1 1 1 - # check_collinearity, hurdle/zi models w/o zi-formula Code diff --git a/tests/testthat/_snaps/compare_performance.md b/tests/testthat/_snaps/compare_performance.md deleted file mode 100644 index 076e60aeb..000000000 --- a/tests/testthat/_snaps/compare_performance.md +++ /dev/null @@ -1,83 +0,0 @@ -# compare_performance - - Code - print(compare_performance(lm1, lm2, lm3)) - Output - # Comparison of Model Performance Indices - - Name | Model | AIC (weights) | AICc (weights) | BIC (weights) | R2 - --------------------------------------------------------------------- - lm1 | lm | 231.5 (<.001) | 231.7 (<.001) | 243.5 (<.001) | 0.619 - lm2 | lm | 106.2 (0.566) | 106.6 (0.611) | 121.3 (0.964) | 0.837 - lm3 | lm | 106.8 (0.434) | 107.6 (0.389) | 127.8 (0.036) | 0.840 - - Name | R2 (adj.) | RMSE | Sigma - -------------------------------- - lm1 | 0.614 | 0.510 | 0.515 - lm2 | 0.833 | 0.333 | 0.338 - lm3 | 0.835 | 0.330 | 0.336 - ---- - - Code - print(compare_performance(lm1, lm2, lm3), table_width = Inf) - Output - # Comparison of Model Performance Indices - - Name | Model | AIC (weights) | AICc (weights) | BIC (weights) | R2 | R2 (adj.) | RMSE | Sigma - ------------------------------------------------------------------------------------------------- - lm1 | lm | 231.5 (<.001) | 231.7 (<.001) | 243.5 (<.001) | 0.619 | 0.614 | 0.510 | 0.515 - lm2 | lm | 106.2 (0.566) | 106.6 (0.611) | 121.3 (0.964) | 0.837 | 0.833 | 0.333 | 0.338 - lm3 | lm | 106.8 (0.434) | 107.6 (0.389) | 127.8 (0.036) | 0.840 | 0.835 | 0.330 | 0.336 - ---- - - Code - print(compare_performance(lm1, lm2, lm3), layout = "vertical") - Output - # Comparison of Model Performance Indices - - Metric | lm1 | lm2 | lm3 - -------------------------------------------------------------- - Model | lm | lm | lm - AIC (weights) | 231.5 (<.001) | 106.2 (0.566) | 106.8 (0.434) - AICc (weights) | 231.7 (<.001) | 106.6 (0.611) | 107.6 (0.389) - BIC (weights) | 243.5 (<.001) | 121.3 (0.964) | 127.8 (0.036) - R2 | 0.619 | 0.837 | 0.840 - R2 (adj.) | 0.614 | 0.833 | 0.835 - RMSE | 0.510 | 0.333 | 0.330 - Sigma | 0.515 | 0.338 | 0.336 - ---- - - Code - print(compare_performance(lm1, lm2, lm3, lm4), layout = "vertical", - table_width = 50) - Message - When comparing models, please note that probably not all models were fit - from same data. - Output - # Comparison of Model Performance Indices - - Metric | lm1 | lm2 - ---------------------------------------------- - Model | lm | lm - AIC (weights) | 231.5 (<.001) | 106.2 (0.408) - AICc (weights) | 231.7 (<.001) | 106.6 (0.454) - BIC (weights) | 243.5 (<.001) | 121.3 (0.933) - R2 | 0.619 | 0.837 - R2 (adj.) | 0.614 | 0.833 - RMSE | 0.510 | 0.333 - Sigma | 0.515 | 0.338 - - Metric | lm3 | lm4 - ---------------------------------------------- - Model | lm | lm - AIC (weights) | 106.8 (0.313) | 107.0 (0.279) - AICc (weights) | 107.6 (0.289) | 107.8 (0.257) - BIC (weights) | 127.8 (0.035) | 128.0 (0.032) - R2 | 0.840 | 0.840 - R2 (adj.) | 0.835 | 0.834 - RMSE | 0.330 | 0.331 - Sigma | 0.336 | 0.337 - diff --git a/tests/testthat/test-check_collinearity.R b/tests/testthat/test-check_collinearity.R index 241aed097..c6b192643 100644 --- a/tests/testthat/test-check_collinearity.R +++ b/tests/testthat/test-check_collinearity.R @@ -205,7 +205,19 @@ test_that("check_collinearity, ci = NULL", { "Tolerance_CI_low", "Tolerance_CI_high" ) ) - expect_snapshot(out) + expect_identical( + capture.output(print(out)), + c( + "# Check for Multicollinearity", + "", + "Low Correlation", + "", + " Term VIF adj. VIF Tolerance", + " N 1 1 1", + " P 1 1 1", + " K 1 1 1" + ) + ) }) test_that("check_collinearity, ci are NA", { diff --git a/tests/testthat/test-check_convergence.R b/tests/testthat/test-check_convergence.R index 1aeb41694..f7b21e41d 100644 --- a/tests/testthat/test-check_convergence.R +++ b/tests/testthat/test-check_convergence.R @@ -19,6 +19,11 @@ test_that("check_convergence", { structure(TRUE, gradient = NA_real_), tolerance = 1e-3 ) + expect_warning( + check_convergence(x = model), + regex = "Argument `x` is deprecated", + fixed = TRUE + ) }) test_that("check_convergence", { diff --git a/tests/testthat/test-check_model.R b/tests/testthat/test-check_model.R index 7ee4be747..d8a157b6c 100644 --- a/tests/testthat/test-check_model.R +++ b/tests/testthat/test-check_model.R @@ -113,6 +113,11 @@ suppressWarnings({ test_that("`check_model()` works if convergence issues", { x <- check_model(m, verbose = FALSE) expect_s3_class(x, "check_model") + expect_warning( + check_model(x = m, verbose = FALSE), + regex = "Argument `x` is deprecated", + fixed = TRUE + ) }) test_that("`check_outliers()` works if convergence issues", { diff --git a/tests/testthat/test-compare_performance.R b/tests/testthat/test-compare_performance.R index 3fce8c4c9..e8f965cc7 100644 --- a/tests/testthat/test-compare_performance.R +++ b/tests/testthat/test-compare_performance.R @@ -43,19 +43,92 @@ test_that("compare_performance", { ) ) + skip_on_cran() + # table split - expect_snapshot(print(compare_performance(lm1, lm2, lm3))) - expect_snapshot(print(compare_performance(lm1, lm2, lm3), table_width = Inf)) + expect_identical( + capture.output(print(compare_performance(lm1, lm2, lm3), table_width = 85)), + c( + "# Comparison of Model Performance Indices", + "", + "Name | Model | AIC (weights) | AICc (weights) | BIC (weights) | R2 | R2 (adj.)", + "---------------------------------------------------------------------------------", + "lm1 | lm | 231.5 (<.001) | 231.7 (<.001) | 243.5 (<.001) | 0.619 | 0.614", + "lm2 | lm | 106.2 (0.566) | 106.6 (0.611) | 121.3 (0.964) | 0.837 | 0.833", + "lm3 | lm | 106.8 (0.434) | 107.6 (0.389) | 127.8 (0.036) | 0.840 | 0.835", + "", + "Name | RMSE | Sigma", + "--------------------", + "lm1 | 0.510 | 0.515", + "lm2 | 0.333 | 0.338", + "lm3 | 0.330 | 0.336" + ) + ) + expect_identical( + capture.output(print(compare_performance(lm1, lm2, lm3), table_width = Inf)), + c( + "# Comparison of Model Performance Indices", + "", + "Name | Model | AIC (weights) | AICc (weights) | BIC (weights) | R2 | R2 (adj.) | RMSE | Sigma", + "-------------------------------------------------------------------------------------------------", + "lm1 | lm | 231.5 (<.001) | 231.7 (<.001) | 243.5 (<.001) | 0.619 | 0.614 | 0.510 | 0.515", + "lm2 | lm | 106.2 (0.566) | 106.6 (0.611) | 121.3 (0.964) | 0.837 | 0.833 | 0.333 | 0.338", + "lm3 | lm | 106.8 (0.434) | 107.6 (0.389) | 127.8 (0.036) | 0.840 | 0.835 | 0.330 | 0.336" + ) + ) # vertical layout - expect_snapshot(print(compare_performance(lm1, lm2, lm3), layout = "vertical")) - expect_snapshot(print( - compare_performance(lm1, lm2, lm3, lm4), - layout = "vertical", - table_width = 50 - )) + expect_identical( + capture.output(print(compare_performance(lm1, lm2, lm3), layout = "vertical")), + c( + "# Comparison of Model Performance Indices", + "", + "Metric | lm1 | lm2 | lm3", + "--------------------------------------------------------------", + "Model | lm | lm | lm", + "AIC (weights) | 231.5 (<.001) | 106.2 (0.566) | 106.8 (0.434)", + "AICc (weights) | 231.7 (<.001) | 106.6 (0.611) | 107.6 (0.389)", + "BIC (weights) | 243.5 (<.001) | 121.3 (0.964) | 127.8 (0.036)", + "R2 | 0.619 | 0.837 | 0.840", + "R2 (adj.) | 0.614 | 0.833 | 0.835", + "RMSE | 0.510 | 0.333 | 0.330", + "Sigma | 0.515 | 0.338 | 0.336" + ) + ) + expect_identical( + capture.output(print( + compare_performance(lm1, lm2, lm3, lm4), + layout = "vertical", + table_width = 50 + )), + c( + "# Comparison of Model Performance Indices", + "", + "Metric | lm1 | lm2", + "----------------------------------------------", + "Model | lm | lm", + "AIC (weights) | 231.5 (<.001) | 106.2 (0.408)", + "AICc (weights) | 231.7 (<.001) | 106.6 (0.454)", + "BIC (weights) | 243.5 (<.001) | 121.3 (0.933)", + "R2 | 0.619 | 0.837", + "R2 (adj.) | 0.614 | 0.833", + "RMSE | 0.510 | 0.333", + "Sigma | 0.515 | 0.338", + "", + "Metric | lm3 | lm4", + "----------------------------------------------", + "Model | lm | lm", + "AIC (weights) | 106.8 (0.313) | 107.0 (0.279)", + "AICc (weights) | 107.6 (0.289) | 107.8 (0.257)", + "BIC (weights) | 127.8 (0.035) | 128.0 (0.032)", + "R2 | 0.840 | 0.840", + "R2 (adj.) | 0.835 | 0.834", + "RMSE | 0.330 | 0.331", + "Sigma | 0.336 | 0.337" + ) + ) - expect_silent(expect_identical( - colnames(compare_performance(lm1, lm2, lm3, lm4, verbose = FALSE)), + expect_silent(expect_named( + compare_performance(lm1, lm2, lm3, lm4, verbose = FALSE), c( "Name", "Model", @@ -84,8 +157,8 @@ test_that("compare_performance", { ) out <- compare_performance(list(lm1, lm2, lm3, lm4), verbose = FALSE) - expect_identical( - colnames(out), + expect_named( + out, c( "Name", "Model", @@ -105,8 +178,8 @@ test_that("compare_performance", { models <- list(lm1, lm2, lm3, lm4) out <- compare_performance(models, verbose = FALSE) - expect_identical( - colnames(out), + expect_named( + out, c( "Name", "Model",