From 3f6c19279f9afc710a3c6813f175ab1787085e9e Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Oct 2023 12:31:47 +0200 Subject: [PATCH] test --- tests/testthat/test-binned_residuals.R | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/testthat/test-binned_residuals.R b/tests/testthat/test-binned_residuals.R index 972f030af..4499441bd 100644 --- a/tests/testthat/test-binned_residuals.R +++ b/tests/testthat/test-binned_residuals.R @@ -17,3 +17,53 @@ test_that("binned_residuals", { tolerance = 1e-4 ) }) + + +test_that("binned_residuals, n_bins", { + data(mtcars) + model <- glm(vs ~ wt + mpg, data = mtcars, family = "binomial") + result <- binned_residuals(model, n_bins = 10) + expect_named( + result, + c("xbar", "ybar", "n", "x.lo", "x.hi", "se", "ci_range", "CI_low", "CI_high", "group") + ) + expect_equal( + result$xbar, + c( + 0.02373, 0.06301, 0.08441, 0.17907, 0.29225, 0.44073, 0.54951, + 0.69701, 0.9168, 0.99204 + ), + tolerance = 1e-4 + ) + expect_equal( + result$ybar, + c( + -0.02373, -0.06301, -0.08441, -0.17907, 0.20775, -0.1074, 0.11715, + 0.30299, -0.25014, 0.00796 + ), + tolerance = 1e-4 + ) +}) + + +test_that("binned_residuals, terms", { + data(mtcars) + model <- glm(vs ~ wt + mpg, data = mtcars, family = "binomial") + result <- binned_residuals(model, term = "mpg") + expect_named( + result, + c("xbar", "ybar", "n", "x.lo", "x.hi", "se", "ci_range", "CI_low", "CI_high", "group") + ) + expect_equal( + result$xbar, + c(12.62, 15.34, 18.1, 20.9, 22.875, 30.06667), + tolerance = 1e-4 + ) + expect_equal( + result$ybar, + c(-0.05435, -0.07866, 0.13925, -0.11861, 0.27763, -0.13786), + tolerance = 1e-4 + ) +}) + +dput(round(result$ybar, 5))