tests/testthat/test-vif_stats.R

testthat::test_that("`vif_stats()` works", {
  testthat::skip_on_cran()

  data(
    vi_smol,
    vi_predictors_numeric
  )

  #general usage

  #from predictors dataframe
  x <- vif_stats(
    df = vi_smol,
    predictors = vi_predictors_numeric,
    quiet = TRUE
  )

  testthat::expect_true(
    is.data.frame(x)
  )

  testthat::expect_true(
    all(colnames(x) %in% c("method", "statistic", "value"))
  )

  #from m results
  m <- cor_matrix(
    df = vi_smol,
    predictors = vi_predictors_numeric,
    quiet = TRUE
  )

  x <- vif_stats(
    df = vi_smol,
    predictors = vi_predictors_numeric,
    quiet = TRUE,
    m = m
  )

  testthat::expect_true(
    is.data.frame(x)
  )

  testthat::expect_true(
    all(colnames(x) %in% c("method", "statistic", "value"))
  )

  #edge cases
  testthat::expect_error(
    x <- vif_stats(),
    regexp = "argument 'df' cannot be NULL"
  )
})

Try the collinear package in your browser

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

collinear documentation built on Dec. 8, 2025, 5:06 p.m.