From 6ee8f8f4446ae21983905de3d59a4ce7cb437266 Mon Sep 17 00:00:00 2001 From: Ken Kellner Date: Wed, 15 Sep 2021 12:03:01 -0400 Subject: Fix plot_marginal tests --- tests/testthat/test_colext.R | 2 +- tests/testthat/test_distsamp.R | 2 +- tests/testthat/test_multinomPois.R | 2 +- tests/testthat/test_occu.R | 2 +- tests/testthat/test_occuRN.R | 2 +- tests/testthat/test_occuTTD.R | 2 +- tests/testthat/test_pcount.R | 2 +- tests/testthat/test_plot_marginal.R | 25 +++++++++++++------------ 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/tests/testthat/test_colext.R b/tests/testthat/test_colext.R index 9d4e94d..85bc4aa 100644 --- a/tests/testthat/test_colext.R +++ b/tests/testthat/test_colext.R @@ -183,7 +183,7 @@ test_that("Fitted/residual methods work with ubmsFitColext",{ dev.off() expect_is(rp, "gg") - expect_is(mp, "gtable") + expect_is(mp, "gg") }) test_that("projected function and sim_state works with ubmsFitColext",{ diff --git a/tests/testthat/test_distsamp.R b/tests/testthat/test_distsamp.R index 2eaa6b8..de7a584 100644 --- a/tests/testthat/test_distsamp.R +++ b/tests/testthat/test_distsamp.R @@ -232,7 +232,7 @@ test_that("Fitted/residual methods work with ubmsFitDistsamp",{ expect_is(rp, "gg") expect_is(rp2, "gg") expect_is(rp3, "gtable") - expect_is(mp, "gtable") + expect_is(mp, "gg") }) test_that("sim_state works for ubmsFitDistsamp",{ diff --git a/tests/testthat/test_multinomPois.R b/tests/testthat/test_multinomPois.R index 71e7ff7..112d2d8 100644 --- a/tests/testthat/test_multinomPois.R +++ b/tests/testthat/test_multinomPois.R @@ -208,7 +208,7 @@ test_that("Fitted/residual methods work with ubmsFitOccu",{ expect_is(rp, "gg") expect_is(rp2, "gg") expect_is(rp3, "gtable") - expect_is(mp, "gtable") + expect_is(mp, "gg") }) test_that("get_pifun_type returns correct value",{ diff --git a/tests/testthat/test_occu.R b/tests/testthat/test_occu.R index 060bdfe..a524c61 100644 --- a/tests/testthat/test_occu.R +++ b/tests/testthat/test_occu.R @@ -179,5 +179,5 @@ test_that("Fitted/residual methods work with ubmsFitOccu",{ expect_is(rp, "gg") expect_is(rp2, "gg") expect_is(rp3, "gtable") - expect_is(mp, "gtable") + expect_is(mp, "gg") }) diff --git a/tests/testthat/test_occuRN.R b/tests/testthat/test_occuRN.R index 8ad0d58..daf3ea0 100644 --- a/tests/testthat/test_occuRN.R +++ b/tests/testthat/test_occuRN.R @@ -172,7 +172,7 @@ test_that("Fitted/residual methods work with ubmsFitOccuRN",{ expect_is(rp, "gg") expect_is(rp2, "gg") expect_is(rp3, "gtable") - expect_is(mp, "gtable") + expect_is(mp, "gg") }) test_that("occuRN spatial works", { diff --git a/tests/testthat/test_occuTTD.R b/tests/testthat/test_occuTTD.R index 22b88ca..d6e770d 100644 --- a/tests/testthat/test_occuTTD.R +++ b/tests/testthat/test_occuTTD.R @@ -192,7 +192,7 @@ test_that("Fitted/residual methods work with ubmsFitOccuTTD",{ expect_is(rp, "gg") expect_is(rp2, "gg") expect_is(rp3, "gtable") - expect_is(mp, "gtable") + expect_is(mp, "gg") }) test_that("occuTTD spatial works", { diff --git a/tests/testthat/test_pcount.R b/tests/testthat/test_pcount.R index 244f7ed..d588050 100644 --- a/tests/testthat/test_pcount.R +++ b/tests/testthat/test_pcount.R @@ -186,7 +186,7 @@ test_that("Fitted/residual methods work with ubmsFitPcount",{ expect_is(rp, "gg") expect_is(rp2, "gg") expect_is(rp3, "gtable") - expect_is(mp, "gtable") + expect_is(mp, "gg") }) test_that("pcount spatial works", { diff --git a/tests/testthat/test_plot_marginal.R b/tests/testthat/test_plot_marginal.R index 2d2c831..f80f832 100644 --- a/tests/testthat/test_plot_marginal.R +++ b/tests/testthat/test_plot_marginal.R @@ -22,17 +22,17 @@ fit2 <- suppressWarnings(stan_occu(~1~1, umf, }) skip_if(!good_fit, "Test setup failed") -test_that("plot_marginal creates grid object",{ +test_that("plot_marginal creates gg or grid object",{ #Multiple covariates pdf(NULL) mp <- plot_marginal(fit, "state") expect_is(mp, "gtable") #Submodel with single covariate mp2 <- plot_marginal(fit, "det") - expect_is(mp2, "gtable") + expect_is(mp2, "gg") #Specific covariate mp3 <- plot_marginal(fit, "state", "x1") - expect_is(mp3, "gtable") + expect_is(mp3, "gg") #No covariates expect_error(plot_marginal(fit2, "state")) dev.off() @@ -40,9 +40,9 @@ test_that("plot_marginal creates grid object",{ test_that("marginal_covariate_plot builds plot for either cov type",{ pdf(NULL) - mcp <- marginal_covariate_plot(fit,"state","x1") + mcp <- marginal_covariate_plot(fit,"state","x1", draws=100) expect_is(mcp, "gg") - mcp2 <- marginal_covariate_plot(fit,"state","x2") + mcp2 <- marginal_covariate_plot(fit,"state","x2", draws=100) expect_is(mcp, "gg") #Covariate not in submodel expect_error(marginal_covariate_plot(fit,"state","fake")) @@ -51,23 +51,24 @@ test_that("marginal_covariate_plot builds plot for either cov type",{ test_that("marg_numeric_plot builds plot for numeric covariate",{ pdf(NULL) - mnp <- marg_numeric_plot(fit, "state", "x1", c(0.025,0.975)) + mnp <- marg_numeric_plot(fit, "state", "x1", c(0.025,0.975), draws=100) expect_is(mnp, "gg") - expect_error(marg_numeric_plot(fit,"state","x2",c(0.025,0.975))) + expect_error(marg_numeric_plot(fit,"state","x2",c(0.025,0.975)), draws=100) dev.off() }) test_that("marg_factor_plot builds plot for factor covariate",{ pdf(NULL) - mfp <- marg_factor_plot(fit, "state", "x2", c(0.025,0.975)) + mfp <- marg_factor_plot(fit, "state", "x2", c(0.025,0.975), draws=100) expect_is(mfp, "gg") - expect_error(marg_factor_plot(fit,"state","x1",c(0.025,0.975))) + expect_error(marg_factor_plot(fit,"state","x1",c(0.025,0.975), draws=100)) dev.off() }) -test_that("get_mean_df gets baseline data frame for plot data",{ - mean_df <- get_mean_df(fit["state"]) - expect_equal(mean_df, data.frame(x1=0.2560184, x2="a"), tol=1e-7) +test_that("get_baseline_df gets baseline data frame for plot data",{ + base_df <- get_baseline_df(fit["state"]) + expect_equal(base_df, data.frame(x1=-0.2301775, + x2=factor("a",levels=c("a","b"))), tol=1e-6) }) test_that("col_is_factor identifies factor column",{ -- cgit v1.2.3