tests/testthat/test-compare-waves.R

test_that("auto chooses linked when stayer covariance is available", {
  dat <- data.frame(
    eeid   = c("a", "b", "c",  "a",  "b",  "d"),
    wave   = c(0,   0,   0,    1,    1,    1),
    metric = c(1,   2,   3,    2,    3,    4)
  )
  
  res <- compare_waves(
    data       = dat,
    wave_0     = 0,
    wave_1     = 1,
    id_col     = "eeid",
    wave_col   = "wave",
    metric_col = "metric",
    method     = "auto"
  )
  
  expect_s3_class(res, "wavecov_result")
  expect_equal(res$method, "linked")
})

test_that("auto chooses reliability when no stayer covariance but reliability is supplied", {
  # Construct a case with no overlap by using disjoint IDs
  dat <- data.frame(
    eeid   = c("a", "b", "c",  "d",  "e",  "f"),
    wave   = c(0,   0,   0,    1,    1,    1),
    metric = c(1,   2,   3,    2,    3,    4)
  )
  
  res <- compare_waves(
    data       = dat,
    wave_0     = 0,
    wave_1     = 1,
    id_col     = "eeid",
    wave_col   = "wave",
    metric_col = "metric",
    method     = "auto",
    reliability = 0.8
  )
  
  expect_s3_class(res, "wavecov_result")
  expect_equal(res$method, "reliability")
})

test_that("auto chooses bounds when neither linked nor reliability is available", {
  dat <- data.frame(
    eeid   = c("a", "b", "c",  "d",  "e",  "f"),
    wave   = c(0,   0,   0,    1,    1,    1),
    metric = c(1,   2,   3,    2,    3,    4)
  )
  
  res <- compare_waves(
    data       = dat,
    wave_0     = 0,
    wave_1     = 1,
    id_col     = "eeid",
    wave_col   = "wave",
    metric_col = "metric",
    method     = "auto"
  )
  
  expect_s3_class(res, "wavecov_bounds_result")
  expect_equal(res$method, "bounds")
})

Try the wavecov package in your browser

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

wavecov documentation built on Nov. 3, 2026, 5:07 p.m.