Debian Codegraph @

tests/testthat/test-survey.R

raw
1 skip_on_cran()
2
3 skip_if_not_installed("modeltests")
4 library(modeltests)
5
6 skip_if_not_installed("survey")
7 suppressPackageStartupMessages(library(survey))
8
9 skip_if_not_installed("MASS")
10
11 data("housing", package = "MASS")
12 design <- svydesign(ids = ~1, weights = ~Freq, data = housing)
13 fit <- svyolr(Sat ~ Infl + Type + Cont, design = design)
14
15 data("api", package = "survey")
16 dstrat <- svydesign(
17 id = ~1,
18 strata = ~stype,
19 weights = ~pw,
20 data = apistrat,
21 fpc = ~fpc
22 )
23 fit_svyglm <- svyglm(
24 formula = sch.wide ~ ell + meals + mobility,
25 design = dstrat,
26 family = quasibinomial()
27 )
28
29
30 test_that("survey tidier arguments", {
31 # check_arguments(tidy.svyolr)
32 check_arguments(glance.svyolr)
33 })
34
35 test_that("tidy.svyolr", {
36 td2 <- tidy(fit, conf.int = TRUE, exponentiate = TRUE)
37 check_tidy_output(td2)
38 })
39
40 test_that("glance.svyolr", {
41 gl <- glance(fit)
42 check_glance_outputs(gl)
43 check_dims(gl, 1, 3)
44 })
45
46 test_that("glance.svyglm: make sure `nobs` is there", {
47 gl <- glance(fit_svyglm)
48 check_glance_outputs(gl)
49 check_dims(gl, 1, 7)
50 expect_true("nobs" %in% colnames(glance(fit_svyglm)))
51 })
52
53 test_that("conf.int merging regression test (#804)", {
54 expect_no_error(tidy(fit_svyglm, conf.int = TRUE))
55 })