Nothing
test_that("compare_waves_batch matches scalar calls for a simple case", {
dat <- data.frame(
eeid = c("a", "b", "c", "a", "b", "c"),
wave = c(0, 0, 0, 1, 1, 1),
bu = c("A", "A", "B", "A", "A", "B"),
metric_name = c("engagement", "engagement", "engagement",
"engagement", "engagement", "engagement"),
metric = c(1.0, 2.0, 3.0,
1.2, 2.1, 2.9)
)
# Scalar call for BU A
dat_A <- subset(dat, bu == "A")
res_scalar <- compare_waves(
data = dat_A,
wave_0 = 0,
wave_1 = 1,
id_col = "eeid",
wave_col = "wave",
metric_col = "metric",
method = "linked"
)
tidy_scalar <- tidy(res_scalar)
wave_pairs <- cbind(
wave_0 = c(0),
wave_1 = c(1)
)
res_batch <- compare_waves_batch(
data = dat,
wave_pairs = wave_pairs,
id_col = "eeid",
wave_col = "wave",
metric_col = "metric",
metric_id_col = "metric_name",
group_cols = "bu",
method = "linked"
)
row_A <- subset(res_batch, bu == "A" & metric_name == "engagement")
expect_equal(nrow(row_A), 1L)
expect_equal(row_A$estimate, res_scalar$estimate)
expect_equal(row_A$se, res_scalar$se)
expect_equal(row_A$method, "linked")
})
test_that("compare_waves_batch reports errors per combination", {
# BU A: only wave 0 (will error)
# BU B: full overlap with stayers (should succeed under method = 'auto')
dat <- data.frame(
eeid = c("a", "b", "c", "d", "c", "d"),
wave = c(0, 0, 0, 0, 1, 1),
bu = c("A", "A", "B", "B", "B", "B"),
metric_name = "engagement",
metric = c(1.0, 2.0,
1.5, 2.0, 1.7, 2.1)
)
wave_pairs <- cbind(wave_0 = 0, wave_1 = 1)
res_batch <- compare_waves_batch(
data = dat,
wave_pairs = wave_pairs,
id_col = "eeid",
wave_col = "wave",
metric_col = "metric",
metric_id_col = "metric_name",
group_cols = "bu",
method = "auto"
)
row_A <- subset(res_batch, bu == "A")
row_B <- subset(res_batch, bu == "B")
expect_equal(nrow(row_A), 1L)
expect_equal(nrow(row_B), 1L)
expect_equal(row_A$status, "error")
expect_true(nchar(row_A$error) > 0)
expect_equal(row_B$status, "ok")
expect_true(is.finite(row_B$estimate))
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.