tests/testthat/test-real_discrete.R

test_that("real discrete ordinal data: lung ph.ecog works with jsd()", {
  skip_if_not_installed("survival")

  lung_df <- survival::lung

  x <- lung_df$ph.ecog[lung_df$sex == 1]
  y <- lung_df$ph.ecog[lung_df$sex == 2]

  res <- jsd(x, y, type = "discrete")

  expect_s3_class(res, "jsd_estimate")
  expect_equal(res$type, "discrete")
  expect_true(is.numeric(res$estimate))
  expect_length(res$estimate, 1)
  expect_true(is.finite(res$estimate))
  expect_true(res$estimate >= 0)
})

test_that("real discrete ordinal data: lung ph.ecog works with jsd_ci()", {
  skip_if_not_installed("survival")

  lung_df <- survival::lung

  x <- lung_df$ph.ecog[lung_df$sex == 1]
  y <- lung_df$ph.ecog[lung_df$sex == 2]

  res <- jsd_ci(x, y, type = "discrete", B = 100, seed = 1)

  expect_s3_class(res, "jsd_ci")
  expect_equal(res$type, "discrete")
  expect_true(is.numeric(res$estimate))
  expect_true(is.finite(res$estimate))
  expect_length(res$conf_int, 2)
  expect_true(all(is.finite(res$conf_int)))
  expect_true(res$conf_int[1] <= res$conf_int[2])
  expect_true(is.numeric(res$boot_se))
  expect_true(is.finite(res$boot_se))
  expect_true(res$boot_se >= 0)
})

test_that("real discrete ordinal data: lung ph.ecog plot_dist runs", {
  skip_if_not_installed("survival")

  lung_df <- survival::lung

  x <- lung_df$ph.ecog[lung_df$sex == 1]
  y <- lung_df$ph.ecog[lung_df$sex == 2]

  expect_no_error(
    plot_dist(
      x, y,
      type = "discrete",
      group_names = c("Male", "Female")
    )
  )
})

Try the jsdtools package in your browser

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

jsdtools documentation built on March 31, 2026, 1:06 a.m.