Debian Codegraph @

tests/testthat/test-survival-survdiff.R

raw
1 skip_on_cran()
2
3 skip_if_not_installed("modeltests")
4 library(modeltests)
5
6 skip_if_not_installed("survival")
7 suppressPackageStartupMessages(library(survival))
8
9 fit <- survdiff(Surv(futime, fustat) ~ rx, data = ovarian)
10 fit2 <- survdiff(Surv(time, status) ~ pat.karno + strata(inst), data = lung)
11 fit3 <- survdiff(
12 Surv(time, status) ~ pat.karno + ph.ecog + strata(inst) + strata(sex),
13 data = lung
14 )
15
16 expect <- survexp(
17 futime ~ 1,
18 rmap = list(
19 age = (accept.dt - birth.dt),
20 sex = 1,
21 year = accept.dt,
22 race = "white"
23 ),
24 jasa,
25 cohort = FALSE,
26 ratetable = survexp.usr
27 )
28
29 fit4 <- survdiff(Surv(jasa$futime, jasa$fustat) ~ offset(expect))
30 fit5 <- survdiff(Surv(futime, fustat) ~ rx + ecog.ps, data = ovarian)
31 rm(expect)
32
33 test_that("survdiff tidier arguments", {
34 check_arguments(tidy.survdiff)
35 check_arguments(glance.survdiff)
36 })
37
38 test_that("tidy.survdiff", {
39 td <- tidy(fit)
40 td2 <- tidy(fit2)
41 td3 <- tidy(fit3)
42 td4 <- tidy(fit4)
43 td5 <- tidy(fit5)
44
45 # The output from tidy.survdiff uses variable names as column names because
46 # the output contains a row for each level of the (statistical) factor. This
47 # output meets the criteria for 'tidy' data. Therefore, strict may be
48 # set to FALSE to allow these tests to pass.
49 check_tidy_output(td, strict = FALSE)
50 check_tidy_output(td2, strict = FALSE)
51 check_tidy_output(td3, strict = FALSE)
52 check_tidy_output(td4)
53 check_tidy_output(td5, strict = FALSE)
54 })
55
56 test_that("glance.survdiff", {
57 gl <- glance(fit)
58 gl2 <- glance(fit2)
59 gl3 <- glance(fit3)
60 gl4 <- glance(fit4)
61 gl5 <- glance(fit5)
62
63 check_glance_outputs(gl, gl2, gl3, gl4, gl5)
64 })