tests/testthat/test-oneway-anova-nonparametric.R

skip_if_not_installed("boot")

# between-subjects ----------------------------------------------

test_that("between-subjects", {
  # without NA
  set.seed(123)
  df1 <- oneway_anova(
    type = "np",
    data = sample_frac(movies_long, 0.1),
    x = genre,
    y = length,
    paired = FALSE
  )

  expect_snapshot(select(df1, -expression))
  expect_snapshot(df1[["expression"]])

  # with NA
  set.seed(123)
  df2 <- oneway_anova(
    type = "np",
    data = msleep,
    x = vore,
    y = sleep_total,
    paired = FALSE,
    conf.level = 0.99
  )

  expect_snapshot(select(df2, -expression))
  expect_snapshot(df2[["expression"]])
})

# within-subjects ----------------------------------------------

test_that("within-subjects", {
  # with NAs
  set.seed(123)
  df1 <- oneway_anova(
    type = "np",
    data = bugs_long,
    x = condition,
    y = desire,
    paired = TRUE,
    conf.level = 0.99
  )

  expect_snapshot(select(df1, -expression))
  expect_snapshot(df1[["expression"]])

  # without NAs
  set.seed(123)
  df2 <- oneway_anova(
    type = "np",
    data = iris_long,
    x = condition,
    y = value,
    paired = TRUE,
    conf.level = 0.90
  )

  expect_snapshot(select(df2, -expression))
  expect_snapshot(df2[["expression"]])
})

Try the statsExpressions package in your browser

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

statsExpressions documentation built on Nov. 14, 2026, 9:08 a.m.