Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 4, 2023
1 parent c36d0d3 commit 3f6c192
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/testthat/test-binned_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 3f6c192

Please sign in to comment.