diff --git a/man/perf.assess.Rd b/man/perf.assess.Rd index 914b96fa..84a7de9e 100644 --- a/man/perf.assess.Rd +++ b/man/perf.assess.Rd @@ -302,7 +302,8 @@ length(liver.toxicity$treatment$Treatment.Group) # 64 samples plsda.res <- plsda(liver.toxicity$gene, liver.toxicity$treatment$Treatment.Group, ncomp = 2) performance <- perf.assess(plsda.res, - validation = "Mfold", folds = 3, nrepeat = 10, # to make sure each fold has all classes represented + # to make sure each fold has all classes represented + validation = "Mfold", folds = 3, nrepeat = 10, seed = 12) # for reproducibility, remove for analysis performance$error.rate$BER @@ -313,7 +314,7 @@ splsda.res <- splsda(liver.toxicity$gene, liver.toxicity$treatment$Treatment.Gro keepX = c(25, 25), ncomp = 2) performance <- perf.assess(splsda.res, - validation = "Mfold", folds = 3, nrepeat = 10, # to make sure each fold has all classes represented + validation = "Mfold", folds = 3, nrepeat = 10, seed = 12) performance$error.rate$BER # can see slight improvement in error rate over PLS-DA example @@ -325,20 +326,22 @@ ncol(liver.toxicity$clinic) # 10 Y variables as output of PLS model pls.res <- pls(liver.toxicity$gene, liver.toxicity$clinic, ncomp = 2) performance <- perf.assess(pls.res, - validation = "Mfold", folds = 3, nrepeat = 10, # to make sure each fold has all classes represented + validation = "Mfold", folds = 3, nrepeat = 10, seed = 12) -performance$measures$Q2$summary # see Q2 which gives indication of predictive ability for each of the 10 Y outputs +# see Q2 which gives indication of predictive ability for each of the 10 Y outputs +performance$measures$Q2$summary ## sPLS example spls.res <- spls(liver.toxicity$gene, liver.toxicity$clinic, ncomp = 2, keepX = c(50, 50)) performance <- perf.assess(spls.res, - validation = "Mfold", folds = 3, nrepeat = 10, # to make sure each fold has all classes represented + validation = "Mfold", folds = 3, nrepeat = 10, seed = 12) -performance$measures$Q2$summary # see Q2 which gives indication of predictive ability for each of the 10 Y outputs +# see Q2 which gives indication of predictive ability for each of the 10 Y outputs +performance$measures$Q2$summary ## block PLS-DA example diff --git a/tests/testthat/test-tune.block.plsda.R b/tests/testthat/test-tune.block.plsda.R index 21ebdf7f..9ede1dd0 100644 --- a/tests/testthat/test-tune.block.plsda.R +++ b/tests/testthat/test-tune.block.plsda.R @@ -42,6 +42,8 @@ test_that("tune.block.plsda works and is the same as perf alone and in tune wrap .expect_numerically_close(tune.res.3$error.rate.per.class$mrna$max.dist[3,2], 0.25) # check can plot outputs + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(tune.res.1)) expect_silent(plot(tune.res.2)) expect_silent(plot(tune.res.3)) diff --git a/tests/testthat/test-tune.block.splsda.R b/tests/testthat/test-tune.block.splsda.R index 6c24f436..a5caf1f5 100644 --- a/tests/testthat/test-tune.block.splsda.R +++ b/tests/testthat/test-tune.block.splsda.R @@ -159,6 +159,8 @@ test_that("tune.block.splsda works independently and in tune wrapper the same", expect_equal(tune11$choice.keepX, tune41$choice.keepX) # check can plot outputs + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(tune41)) expect_silent(plot(tune11)) diff --git a/tests/testthat/test-tune.mint.plsda.R b/tests/testthat/test-tune.mint.plsda.R index 34ee9b42..d65b575b 100644 --- a/tests/testthat/test-tune.mint.plsda.R +++ b/tests/testthat/test-tune.mint.plsda.R @@ -36,6 +36,8 @@ test_that("tune.mint.plsda works and is the same perf alone and in tune wrapper" .expect_numerically_close(tune.res.3$global.error$BER[1,1], 0.3803556) # check can plot outputs + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(tune.res.1)) expect_silent(plot(tune.res.2)) expect_silent(plot(tune.res.3)) diff --git a/tests/testthat/test-tune.mint.splsda.R b/tests/testthat/test-tune.mint.splsda.R index 58630e7e..8719f6bf 100644 --- a/tests/testthat/test-tune.mint.splsda.R +++ b/tests/testthat/test-tune.mint.splsda.R @@ -21,7 +21,9 @@ test_that("tune.mint.splsda works", code = { expect_equal(out$choice.ncomp$ncomp, 1) # check can plot - expect_silent(plot(out)) + pdf(NULL) + on.exit(dev.off()) + expect_error(plot(out), NA) # makes note about not being able to plot SD bars }) @@ -47,7 +49,9 @@ test_that("tune.mint.splsda works with custom alpha", code = { expect_equal(out$choice.ncomp$ncomp, 1) # check can plot - expect_silent(plot(out)) + pdf(NULL) + on.exit(dev.off()) + expect_error(plot(out), NA) # makes note about not being able to plot SD bars }) diff --git a/tests/testthat/test-tune.pca.R b/tests/testthat/test-tune.pca.R index 98b61e45..77e9afac 100644 --- a/tests/testthat/test-tune.pca.R +++ b/tests/testthat/test-tune.pca.R @@ -9,6 +9,8 @@ test_that("tune.pca and tune(method='pca') are equivalent", { expect_equal(object1$ncomp, object2$ncomp) expect_equal(object1$sdev[1], object2$sdev[1]) # check can plot outputs without errors + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(object1)) expect_silent(plot(object2)) }) diff --git a/tests/testthat/test-tune.pls.R b/tests/testthat/test-tune.pls.R index 0bdb1012..9b0fba35 100644 --- a/tests/testthat/test-tune.pls.R +++ b/tests/testthat/test-tune.pls.R @@ -31,6 +31,8 @@ test_that("tune.pls works and is the same as perf alone and in tune wrapper", co .expect_numerically_close(tune.res.3$measures$Q2$summary[1,3], -0.1304012) # check can plot outputs + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(tune.res.1)) expect_silent(plot(tune.res.2)) expect_silent(plot(tune.res.3)) diff --git a/tests/testthat/test-tune.plsda.R b/tests/testthat/test-tune.plsda.R index d84c1e89..9ee1a112 100644 --- a/tests/testthat/test-tune.plsda.R +++ b/tests/testthat/test-tune.plsda.R @@ -43,6 +43,8 @@ test_that("tune.plsda works and is the same perf alone and in tune wrapper", cod .expect_numerically_close(tune.plsda.res.3$error.rate$overall[1,1], 0.5106383) # check can plot + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(tune.plsda.res.1)) expect_silent(plot(tune.plsda.res.2)) expect_silent(plot(tune.plsda.res.3)) diff --git a/tests/testthat/test-tune.rcc.R b/tests/testthat/test-tune.rcc.R index 7c241f45..7cf83a5c 100644 --- a/tests/testthat/test-tune.rcc.R +++ b/tests/testthat/test-tune.rcc.R @@ -16,6 +16,8 @@ test_that("tune.rcc works with Mfold method", code = { expect_equal(tune.rcc.res$grid1, c(0.00100, 0.25075, 0.50050, 0.75025, 1.00000)) # check can plot + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(tune.rcc.res)) }) @@ -34,6 +36,8 @@ test_that("tune.rcc works with loo method", code = { expect_equal(tune.rcc.res$grid1, c(0.00100, 0.25075, 0.50050, 0.75025, 1.00000)) # check can plot + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(tune.rcc.res)) }) @@ -56,6 +60,8 @@ test_that("tune.rcc works in parallel same as in series", code = { expect_equal(tune.rcc.res$grid2, tune.rcc.res.parallel$grid2) # check can plot + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(tune.rcc.res)) expect_silent(plot(tune.rcc.res.parallel)) }) @@ -86,6 +92,8 @@ test_that("tune.rcc and tune(method='rcc') are equivalent", { expect_equal(tune.rcc.res.1$grid2, tune.rcc.res.2$grid2) # check can plot + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(tune.rcc.res.1)) expect_silent(plot(tune.rcc.res.2)) diff --git a/tests/testthat/test-tune.spca.R b/tests/testthat/test-tune.spca.R index 61e415db..d4fd6c75 100644 --- a/tests/testthat/test-tune.spca.R +++ b/tests/testthat/test-tune.spca.R @@ -20,6 +20,8 @@ test_that("tune.spca works in serial and parallel", { expect_equal(object_parallel$choice.keepX[[2]], 5) .expect_numerically_close(object_parallel$cor.comp$comp1[1,2], 0.3994544) # test can plot outputs + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(object_serial)) expect_silent(plot(object_parallel)) }) @@ -81,6 +83,8 @@ test_that("tune.spca and tune(method='spca') are equivalent", { expect_equal(object1$choice.keepX[[2]], object2$choice.keepX[[2]]) .expect_numerically_close(object1$cor.comp$comp1[3,3], object2$cor.comp$comp1[3,3]) # test can plot outputs + pdf(NULL) + on.exit(dev.off()) expect_silent(plot(object1)) expect_silent(plot(object2)) }) diff --git a/tests/testthat/test-tune.splsda.R b/tests/testthat/test-tune.splsda.R index 4abe2f18..3116f99f 100644 --- a/tests/testthat/test-tune.splsda.R +++ b/tests/testthat/test-tune.splsda.R @@ -31,11 +31,13 @@ test_that("tune.splsda works and is the same in parallel and when run in tune wr method = "splsda") - # check outputs + # check outputs format expect_equal(class(tune.splsda.res.1), "tune.splsda") expect_equal(class(tune.splsda.res.2), "tune.splsda") expect_equal(class(tune.splsda.res.3), "tune.splsda") expect_equal(class(tune.splsda.res.4), "tune.splsda") + + # check output values expect_equal(unname(tune.splsda.res.1$choice.keepX), c(10,15)) expect_equal(unname(tune.splsda.res.2$choice.keepX), c(10,15)) expect_equal(unname(tune.splsda.res.3$choice.keepX), c(10,15)) @@ -46,10 +48,10 @@ test_that("tune.splsda works and is the same in parallel and when run in tune wr .expect_numerically_close(tune.splsda.res.4$error.rate[1,1], 0.3111111) # check can plot outputs - expect_silent(plot(tune.splsda.res.1)) - expect_silent(plot(tune.splsda.res.2)) - expect_silent(plot(tune.splsda.res.3)) - expect_silent(plot(tune.splsda.res.4)) + expect_is(plot(tune.splsda.res.1), "ggplot") + expect_is(plot(tune.splsda.res.2), "ggplot") + expect_is(plot(tune.splsda.res.3), "ggplot") + expect_is(plot(tune.splsda.res.4), "ggplot") })