mixed <- function() { d <- data.frame(variable = rep(c("wagt", "wrr"), each = 5), obs = c(seq(9000, 17000, length.out = 5), seq(4000, 9000, length.out = 5)), stringsAsFactors = FALSE) d$pred <- d$obs * 1.05 d } test_that("pooling statistics across variables warns", { expect_warning(gof("obs", "pred", data = mixed()), "more than one variable") }) test_that("grouping by variable is accepted silently", { expect_silent(g <- gof("obs", "pred", data = mixed(), by = "variable")) expect_equal(nrow(g), 2L) expect_false(isTRUE(all.equal(g$rmse[1], g$rmse[2]))) }) test_that("a single variable never warns", { d <- mixed()[mixed()$variable == "wrr", ] expect_silent(gof("obs", "pred", data = d)) }) test_that("plot_one2one facets by variable rather than mixing units", { expect_message(plot_one2one(mixed()), "do not share units") p <- suppressMessages(plot_one2one(mixed())) expect_equal(nlevels(ggplot2::ggplot_build(p)$data[[1]]$PANEL), 2L) }) test_that("an explicit facet is respected", { d <- mixed(); d$phase <- rep(c("Calibration", "Validation"), 5) expect_silent(p <- plot_one2one(d[d$variable == "wrr", ], facet = "phase")) expect_equal(nlevels(ggplot2::ggplot_build(p)$data[[1]]$PANEL), 2L) }) test_that("per-variable statistics differ from the pooled figure", { g1 <- suppressWarnings(gof("obs", "pred", data = mixed())) g2 <- gof("obs", "pred", data = mixed(), by = "variable") # the pooled RMSE sits between the two, and its R2 is inflated expect_true(g1$rmse > min(g2$rmse) && g1$rmse < max(g2$rmse)) })