test_that("srh.kway.full works for 1-, 2- and 3-factor designs", { data(mimicry, package = "factorH") # 1 factor f1 <- srh.kway.full(liking ~ condition, data = mimicry) expect_type(f1, "list") expect_true(all(c("anova","summary","posthoc_cells","posthoc_simple","meta") %in% names(f1))) expect_s3_class(f1$anova, "data.frame") expect_s3_class(f1$summary, "data.frame") expect_true(is.list(f1$posthoc_cells)) expect_identical(f1$posthoc_simple, "[not applicable]") expect_true(is.list(f1$meta)) expect_equal(f1$meta$n, nrow(na.omit(mimicry[c("liking","condition")]))) # 2 factors, default type = 2 -> srh.effsize path f2 <- srh.kway.full(liking ~ gender + condition, data = mimicry) expect_s3_class(f2$anova, "data.frame") expect_true(is.list(f2$posthoc_cells)) expect_true(all(c("gender","condition","gender:condition") %in% names(f2$posthoc_cells))) expect_true(is.list(f2$posthoc_simple)) expect_true("COMPARE(gender) | BY(condition)" %in% names(f2$posthoc_simple)) expect_true("COMPARE(condition) | BY(gender)" %in% names(f2$posthoc_simple)) expect_true(is.list(f2$meta$design)) expect_true(all(c("n_cells","n_observed","n_empty","prop_empty", "min_cell_n","min_nonempty_cell_n", "n_singletons","n_lt3","n_lt5") %in% names(f2$meta$design))) # 2 factors, type = 3 -> srh.kway path f2_t3 <- srh.kway.full(liking ~ gender + condition, data = mimicry, type = 3) expect_s3_class(f2_t3$anova, "data.frame") expect_true("Effect" %in% names(f2_t3$anova)) expect_true(any(f2_t3$anova$Effect == "gender:condition")) # 3 factors f3 <- srh.kway.full(liking ~ gender + condition + age_cat, data = mimicry) expect_s3_class(f3$anova, "data.frame") expect_true(all(c("gender","condition","age_cat", "gender:condition","gender:age_cat","condition:age_cat", "gender:condition:age_cat") %in% names(f3$posthoc_cells))) expect_true(is.list(f3$posthoc_simple)) expect_true("COMPARE(gender) | BY(condition x age_cat)" %in% names(f3$posthoc_simple)) expect_true(is.list(f3$meta$design)) }) test_that("srh.kway.full validates inputs and level counts", { data(mimicry, package = "factorH") # non-numeric response expect_error(srh.kway.full(gender ~ condition, data = mimicry), "must be numeric", ignore.case = TRUE) # factor with < 2 levels mm <- subset(mimicry, gender == "female") expect_error(srh.kway.full(liking ~ gender + condition, data = mm), "< 2 levels", ignore.case = TRUE) # factor with too many levels (force via small max_levels) expect_error(srh.kway.full(liking ~ condition, data = mimicry, max_levels = 1), ">* levels|> 1 levels", ignore.case = TRUE) # invalid type expect_error(srh.kway.full(liking ~ gender + condition, data = mimicry, type = 1), "type.*2 or 3", ignore.case = TRUE) }) test_that("srh.kway.full returns data.frames for summary and anova", { data(mimicry, package = "factorH") f2 <- srh.kway.full(liking ~ gender + condition, data = mimicry) expect_s3_class(f2$summary, "data.frame") expect_true(all(c("Effect","count","mean","median","mean_rank") %in% names(f2$summary))) }) test_that("srh.kway.full propagates scope to simple-effects post hocs", { data(mimicry, package = "factorH") fw <- srh.kway.full(liking ~ gender + condition, data = mimicry, scope = "within") fg <- srh.kway.full(liking ~ gender + condition, data = mimicry, scope = "global") expect_true(is.list(fw$posthoc_simple)) expect_true(is.list(fg$posthoc_simple)) expect_identical(fw$meta$scope, "within") expect_identical(fg$meta$scope, "global") })