diff --git a/tests/testthat/test-survey.R b/tests/testthat/test-survey.R new file mode 100644 index 000000000..18e5c7dca --- /dev/null +++ b/tests/testthat/test-survey.R @@ -0,0 +1,37 @@ +skip_if_not_installed("withr") + +withr::with_environment( + new.env(), + test_that("model_parameters svytable", { + skip_if_not_installed("survey") + # svychisq is called in model_parameters + svychisq <- survey::svychisq + + data(api, package = "survey") + dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) + m <- survey::svytable(~ sch.wide + stype, dclus1) + mp <- model_parameters(m) + expect_named(mp, c("F", "df", "df_error", "p", "Method")) + expect_equal(mp$p, 0.02174746, tolerance = 1e-3) + }) +) + +withr::with_environment( + new.env(), + test_that("model_parameters, bootstrap svyglm", { + data(api, package = "survey") + dstrat <- survey::svydesign( + id = ~1, + strata = ~stype, + weights = ~pw, + data = apistrat, + fpc = ~fpc + ) + + model_svyglm <- suppressWarnings(survey::svyglm(sch.wide ~ ell + meals + mobility, + design = dstrat, + family = binomial(link = "logit") + )) + expect_message(parameters(model_svyglm, bootstrap = TRUE), regex = "arguments are not supported") + }) +) diff --git a/tests/testthat/test-svytable.R b/tests/testthat/test-svytable.R deleted file mode 100644 index 8e6792b94..000000000 --- a/tests/testthat/test-svytable.R +++ /dev/null @@ -1,12 +0,0 @@ -test_that("model_parameters", { - skip_if_not_installed("survey") - # svychisq is called in model_parameters - svychisq <<- survey::svychisq - - data(api, package = "survey") - dclus1 <<- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) - m <- survey::svytable(~ sch.wide + stype, dclus1) - mp <- model_parameters(m) - expect_equal(colnames(mp), c("F", "df", "df_error", "p", "Method")) - expect_equal(mp$p, 0.02174746, tolerance = 1e-3) -})