| 1 |
skip_on_cran() |
| 2 |
|
| 3 |
# Matrix ABI version may differ (#1204) |
| 4 |
skip_if_not_r_version("4.4.0") |
| 5 |
|
| 6 |
skip_if_not_installed("modeltests") |
| 7 |
library(modeltests) |
| 8 |
|
| 9 |
skip_if_not_installed("joineRML") |
| 10 |
suppressPackageStartupMessages(library(joineRML)) |
| 11 |
|
| 12 |
# NOTE: the models used in these tests are created in |
| 13 |
# `data-raw/fit_and_save_long_running_models.R`, and then are saved to |
| 14 |
# `tests/testthat/fixtures/mjoint_fits.rda` |
| 15 |
load(test_path("fixtures", "mjoint_fits.rda")) |
| 16 |
|
| 17 |
hvd <- heart.valve |> |
| 18 |
dplyr::filter(!is.na(log.grad), !is.na(log.lvmi), num <= 50) |
| 19 |
|
| 20 |
test_that("mjoint tidier arguments", { |
| 21 |
check_arguments(tidy.mjoint) |
| 22 |
check_arguments(glance.mjoint) |
| 23 |
check_arguments(augment.mjoint) |
| 24 |
}) |
| 25 |
|
| 26 |
test_that("tidy.mjoint", { |
| 27 |
td <- tidy(mjoint_fit) |
| 28 |
tds <- tidy(mjoint_fit, component = "survival") |
| 29 |
tdl <- tidy(mjoint_fit, component = "longitudinal") |
| 30 |
|
| 31 |
tdsbs <- tidy( |
| 32 |
mjoint_fit, |
| 33 |
component = "survival", |
| 34 |
boot_se = mjoint_fit_bs_se |
| 35 |
) |
| 36 |
|
| 37 |
tdlbs <- tidy( |
| 38 |
mjoint_fit, |
| 39 |
component = "longitudinal", |
| 40 |
boot_se = mjoint_fit_bs_se |
| 41 |
) |
| 42 |
|
| 43 |
check_tidy_output(td) |
| 44 |
check_tidy_output(tds) |
| 45 |
check_tidy_output(tdl) |
| 46 |
check_tidy_output(tdsbs) |
| 47 |
check_tidy_output(tdlbs) |
| 48 |
|
| 49 |
td2 <- tidy(mjoint_fit2) |
| 50 |
td2s <- tidy(mjoint_fit2, component = "survival") |
| 51 |
td2l <- tidy(mjoint_fit2, component = "longitudinal") |
| 52 |
|
| 53 |
td2sbs <- tidy( |
| 54 |
mjoint_fit2, |
| 55 |
component = "survival", |
| 56 |
boot_se = mjoint_fit2_bs_se, |
| 57 |
conf.int = TRUE |
| 58 |
) |
| 59 |
|
| 60 |
td2lbs <- tidy( |
| 61 |
mjoint_fit2, |
| 62 |
component = "longitudinal", |
| 63 |
boot_se = mjoint_fit2_bs_se, |
| 64 |
conf.int = TRUE |
| 65 |
) |
| 66 |
|
| 67 |
check_tidy_output(td2) |
| 68 |
check_tidy_output(td2s) |
| 69 |
check_tidy_output(td2l) |
| 70 |
check_tidy_output(td2sbs) |
| 71 |
check_tidy_output(td2lbs) |
| 72 |
|
| 73 |
expect_snapshot(error = TRUE, tidy(mjoint_fit, boot_se = "cat")) |
| 74 |
}) |
| 75 |
|
| 76 |
|
| 77 |
test_that("glance.mjoint", { |
| 78 |
gl <- glance(mjoint_fit) |
| 79 |
gl2 <- glance(mjoint_fit2) |
| 80 |
|
| 81 |
check_glance_outputs(gl, strict = FALSE) |
| 82 |
check_glance_outputs(gl2, strict = FALSE) |
| 83 |
}) |
| 84 |
|
| 85 |
|
| 86 |
test_that("augment.mjoint", { |
| 87 |
au <- augment(mjoint_fit) |
| 88 |
au2 <- augment(mjoint_fit2) |
| 89 |
|
| 90 |
expect_snapshot(error = TRUE, augment(mjoint_fit, data = NULL)) |
| 91 |
|
| 92 |
check_tibble(au, method = "augment", strict = FALSE) |
| 93 |
check_tibble(au, method = "augment", strict = FALSE) |
| 94 |
}) |