Debian Codegraph @

tests/testthat/test-epiR.R

raw
1 skip_on_cran()
2
3 skip_if_not_installed("epiR")
4
5 skip_if_not_installed("modeltests")
6 library(modeltests)
7
8 dat <- matrix(c(13, 2163, 5, 3349), nrow = 2, byrow = TRUE)
9 rownames(dat) <- c("DF+", "DF-")
10 colnames(dat) <- c("FUS+", "FUS-")
11
12 skip_if_not_installed("MASS")
13 suppressPackageStartupMessages(library(MASS))
14 birthwt <- MASS::birthwt
15
16 birthwt$low <- factor(birthwt$low, levels = c(1, 0))
17 birthwt$smoke <- factor(birthwt$smoke, levels = c(1, 0))
18 birthwt$race <- factor(birthwt$race, levels = c(1, 2, 3))
19 tab1 <- table(birthwt$smoke, birthwt$low, dnn = c("Smoke", "Low BW"))
20 tab2 <- table(
21 birthwt$smoke,
22 birthwt$low,
23 birthwt$race,
24 dnn = c("Smoke", "Low BW", "Race")
25 )
26
27 suppressPackageStartupMessages(library(epiR))
28 fit1 <- epi.2by2(
29 dat = as.table(dat),
30 method = "cross.sectional",
31 conf.level = 0.95,
32 units = 100,
33 outcome = "as.columns"
34 )
35 fit2 <- epi.2by2(
36 dat = tab1,
37 method = "cohort.count",
38 conf.level = 0.95,
39 units = 100,
40 outcome = "as.columns"
41 )
42 fit3 <- epi.2by2(
43 dat = tab2,
44 method = "cohort.count",
45 conf.level = 0.95,
46 units = 100,
47 outcome = "as.columns"
48 )
49
50 test_that("epi2by2 arguments", {
51 check_arguments(tidy.epi.2by2)
52 })
53
54 test_that("tidy.epi2by2", {
55 tidy1 <- tidy(fit1)
56 tidy2 <- tidy(fit2)
57 tidy3 <- tidy(fit3, parameters = "stat")
58
59 check_tidy_output(tidy1)
60 check_tidy_output(tidy2)
61 check_tidy_output(tidy3)
62
63 # check_dims(tidy1, 13, 4)
64 })