tests/testthat/test-score_cramer.R

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

  data(vi_smol)

  #perfect prediction
  x <- score_cramer(
    o = vi_smol$vi_categorical,
    p = vi_smol$vi_categorical
  )

  testthat::expect_equal(x, 1, tolerance = 1e-10)

  #random prediction
  x <- score_cramer(
    o = vi_smol$vi_categorical,
    p = vi_smol$koppen_zone
  )

  testthat::expect_true(
    x < 1
  )

  #error
  testthat::expect_error(
    x <- score_cramer(
      o = NULL,
      p = vi_smol$vi_categorical
    )
  )

  testthat::expect_error(
    x <- score_cramer(
      o = vi_smol$vi_categorical,
      p = 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.