tests/testthat/test-statistics.R

test_that("paired and nonparametric tests return r4vn_stat", {
  d <- data.frame(
    before = c(18, 20, 15, 22, 17, 19, 24, 16),
    after = c(15, 18, 14, 19, 16, 17, 20, 15),
    group = factor(rep(c("A", "B"), each = 4)),
    score = c(12, 15, 11, 19, 18, 21, 14, 17)
  )
  expect_s3_class(ttest(before, after, data = d, paired = TRUE, show = FALSE), "r4vn_stat")
  expect_s3_class(ranksum(score, by = group, data = d, show = FALSE), "r4vn_stat")
  expect_s3_class(signrank(before, after, data = d, show = FALSE), "r4vn_stat")
  expect_s3_class(kwallis(score, by = group, data = d, show = FALSE), "r4vn_stat")
  expect_s3_class(swilk(score, data = d, show = FALSE), "r4vn_stat")
})

test_that("friedman works in wide format", {
  d <- data.frame(
    baseline = c(12, 14, 11, 15, 13, 16),
    month1 = c(11, 13, 10, 14, 12, 14),
    month3 = c(9, 12, 9, 12, 11, 13)
  )
  expect_s3_class(friedman(baseline, month1, month3, data = d, show = FALSE), "r4vn_stat")
})

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.