tests/testthat/test-weighting-args.R

test_that("weighting function errors", {
  y <- rnorm(10)
  x1 <- runif(10)
  x2 <- runif(10)
  m <- lm(y ~ x1 + x2)

  expect_error(
    calculate_weights("string", "a"),
    class = "regweight_model_argument"
  )

  expect_error(
    calculate_weights(m, "a"),
    class = "regweight_term_argument"
  )

  expect_error(
    calculate_weights(m, "x"),
    class = "regweight_term_argument"
  )

  expect_error(
    calculate_weights("string", "x"),
    class = "regweight_model_argument"
  )

  expect_error(
    calculate_weights(m, 3),
    class = "regweight_term_argument"
  )

  class(m) <- "lm_robust"
  expect_error(
    calculate_weights(m, 3),
    class = "regweight_term_argument"
  )
})

Try the regweight package in your browser

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

regweight documentation built on March 18, 2022, 7:53 p.m.