tests/testthat/test-bias.R

fit <- lm(Sepal.Length ~ ., data = iris)
v <- c("Sepal.Width", "Species")

test_that("bias() is consistent with feature_effects()", {
  b <- bias(iris[v], resid = iris$Sepal.Length - predict(fit, iris))
  marg <- feature_effects(
    fit, v = v, data = iris, y = iris$Sepal.Length, pd_n = 0, ale_n = 0
  )
  for (z in v) {
    out <- b[[z]]
    attr(out, "discrete") <- NULL
    expect_equal(out, marg[[z]][names(marg[[z]]) %in% colnames(b[[z]])])
  }
})

test_that("single vector input works", {
  r <- rep(0, nrow(iris))
  out1 <- bias(iris$Species, resid = r)
  names(out1) <- "Species"
  out2 <- bias(iris$Species, resid = r, x_name = "Species")
  out3 <- bias(iris["Species"], resid = r)
  expect_equal(out1, out2)
  expect_equal(out1, out3)
})

Try the effectplots package in your browser

Any scripts or data that you put into this service are public.

effectplots documentation built on April 12, 2025, 2:13 a.m.