From 386bc6feefa6b8fe11ee6b5c4780850afbd35549 Mon Sep 17 00:00:00 2001 From: Valentijn de Jong Date: Thu, 15 Feb 2024 20:53:57 +0100 Subject: [PATCH] Update test_metapred_3.R Added tests for multiple generalizability and performance functions in metapred. This should prevent the fixed bug from reoccuring. --- tests/testthat/test_metapred_3.R | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/testthat/test_metapred_3.R b/tests/testthat/test_metapred_3.R index 653a89c..658a344 100644 --- a/tests/testthat/test_metapred_3.R +++ b/tests/testthat/test_metapred_3.R @@ -57,6 +57,12 @@ test_that("metapred can handle different perfFUN", { expect_is(mp <- metamisc:::metapred(td, strata = "X4", scope = f, formula = f, family = binomial, perfFUN = "auc" , selFUN = "which.max", meta.method = "FE") , "metapred") + + expect_is(mp <- metamisc:::metapred(td, strata = "X4", scope = f, formula = f, family = binomial, + perfFUN = list("mse", "auc"), + selFUN = "which.max", meta.method = "FE") + , "metapred") + }) test_that("metapred can handle multiple genFUN.", { @@ -79,6 +85,56 @@ test_that("metapred can handle multiple genFUN.", { # , "metapred") }) +test_that("metapred can handle multiple genFUN and perfFUN.", { + genFUN <- list(abs.mean = "abs.mean", coef.var.mean = "coef.var.mean") + perfFUN = list("mse", "auc") + + expect_is(mp <- metamisc:::metapred(data = td, + strata = "X4", + scope = f, + formula = f, + family = binomial, + genFUN = genFUN, + perfFUN = perfFUN, + meta.method = "FE", + gen.of.perf = "first") # default + , "metapred") + + expect_s3_class(perf(mp), "data.frame") + expect_type(mp$FUN$perfFUN[[2]], "closure") + expect_length(gen(mp, 0), 2) + + expect_is(mp <- metamisc:::metapred(data = td, + strata = "X4", + scope = f, + formula = f, + family = binomial, + genFUN = genFUN, + perfFUN = perfFUN, + meta.method = "FE", + gen.of.perf = "factorial") + , "metapred") + + expect_s3_class(perf(mp), "data.frame") + expect_type(mp$FUN$perfFUN[[2]], "closure") + expect_length(gen(mp, 0), 4) + + expect_is(mp <- metamisc:::metapred(data = td, + strata = "X4", + scope = f, + formula = f, + family = binomial, + genFUN = genFUN, + perfFUN = perfFUN, + meta.method = "FE", + gen.of.perf = "respective") + , "metapred") + expect_length(gen(mp, 0), 2) + + expect_s3_class(perf(mp), "data.frame") + expect_type(mp$FUN$perfFUN[[2]], "closure") +}) + test_that("metapred can handle different distributions.", { expect_true(is.list(mp <- metapred(data = td, strata = "X4", family = binomial, max.steps = 0, meta.method = "FE") )) # binomial