tests/testthat/test-poisson-family-compat.R

test_that("R4VN poisson family mode accepts character and function links", {
  f1 <- R4VN::poisson()
  expect_identical(f1$family, "poisson")
  expect_identical(f1$link, "log")

  f2 <- R4VN::poisson(link = "identity")
  expect_identical(f2$link, "identity")

  f3 <- R4VN::poisson(link = "sqrt")
  expect_identical(f3$link, "sqrt")

  # Critical MASS compatibility path.
  f4 <- R4VN::poisson(link = log)
  expect_identical(f4$link, "log")

  f5 <- R4VN::poisson(link = identity)
  expect_identical(f5$link, "identity")

  f6 <- R4VN::poisson(link = sqrt)
  expect_identical(f6$link, "sqrt")
})

test_that("MASS glm.nb is compatible when R4VN poisson is visible", {
  skip_if_not_installed("MASS")

  set.seed(2026)
  d <- data.frame(
    y = MASS::rnegbin(160, mu = 5, theta = 1.2),
    x = stats::rnorm(160)
  )

  expect_no_error(
    fit <- MASS::glm.nb(y ~ x, data = d)
  )

  expect_s3_class(fit, "negbin")
  expect_identical(fit$family$link, "log")
})

Try the R4VN package in your browser

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

R4VN documentation built on Sept. 30, 2026, 5:13 p.m.