Skip to content

Commit

Permalink
Merge branch 'main' into 79-add-binary-endpoints-to-wrapper-anchored-…
Browse files Browse the repository at this point in the history
…function
  • Loading branch information
gravesti authored Jul 18, 2024
2 parents 0824ad0 + 88f7c55 commit d398b9b
Show file tree
Hide file tree
Showing 9 changed files with 4,915 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ repos:
.*\.rds|
.*\.Rds|
.*\.sh|
.*\.RData
.*\.RData|
.*\.svg
)$
- id: lintr
- id: readme-rmd-rendered
Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Suggests:
dplyr,
survminer,
flexsurv,
tibble
tibble,
vdiffr
VignetteBuilder:
knitr
biocViews:
Expand Down
4 changes: 2 additions & 2 deletions R/plot_km2.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ kmplot2 <- function(weights_object,
kmlist_1_2 <- list(
setNames(
all_km[c(4, 1, 3, 5)],
c(trt_ipd, trt_common, paste0(trt_ipd, " (weighted)"), paste0(trt_common, " (weighted)"))
c(trt_common, trt_ipd, paste0(trt_ipd, " (weighted)"), paste0(trt_common, " (weighted)"))
),
setNames(all_km[c(6, 2)], c(trt_common, trt_agd))
)
Expand All @@ -119,7 +119,7 @@ kmplot2 <- function(weights_object,
if (km_layout %in% c("by_arm", "all")) {
kmlist_3_4 <- list(
setNames(all_km[c(2, 1, 3)], c(trt_agd, trt_ipd, paste0(trt_ipd, " (weighted)"))),
setNames(all_km[c(6, 4, 4)], paste(trt_common, c("(AgD)", "(IPD)", "(IPD,weighted)")))
setNames(all_km[c(6, 4, 5)], paste(trt_common, c("(AgD)", "(IPD)", "(IPD,weighted)")))
)
names(kmlist_3_4) <- c(
paste0("Kaplan-Meier Curves \n(", trt_ipd, " vs ", trt_agd, ")"),
Expand Down
1,772 changes: 1,772 additions & 0 deletions tests/testthat/_snaps/plot_km/kmplot2-all.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
991 changes: 991 additions & 0 deletions tests/testthat/_snaps/plot_km/kmplot2-by-am.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
991 changes: 991 additions & 0 deletions tests/testthat/_snaps/plot_km/kmplot2-by-trial.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
614 changes: 614 additions & 0 deletions tests/testthat/_snaps/plot_km/ph-diagplot-lch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
428 changes: 428 additions & 0 deletions tests/testthat/_snaps/plot_km/ph-diagplot-schoenfeld.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 113 additions & 4 deletions tests/testthat/test-plot_km.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,132 @@ test_that("ph_diagplot_lch works without error", {
original_par <- par()
load(system.file("extdata", "combined_data_tte.rda", package = "maicplus", mustWork = TRUE))
kmobj <- survfit(Surv(TIME, EVENT) ~ ARM, combined_data_tte, conf.type = "log-log")
ph_diagplot_lch(kmobj,
time_scale = "month", log_time = TRUE,
endpoint_name = "OS", subtitle = "(Before Matching)"
expect_no_error(
ph_diagplot_lch(
kmobj,
time_scale = "month", log_time = TRUE,
endpoint_name = "OS", subtitle = "(Before Matching)"
)
)

expect_equal(original_par, par())

skip_if_not_installed("vdiffr")
vdiffr::expect_doppelganger(
title = "ph_diagplot_lch",
fig = function() {
ph_diagplot_lch(
kmobj,
time_scale = "month", log_time = TRUE,
endpoint_name = "OS", subtitle = "(Before Matching)"
)
}
)
})

test_that("ph_diagplot_schoenfeld works without error", {
original_par <- par()
load(system.file("extdata", "combined_data_tte.rda", package = "maicplus", mustWork = TRUE))
unweighted_cox <- coxph(Surv(TIME, EVENT == 1) ~ ARM, data = combined_data_tte)
expect_no_error(
ph_diagplot_schoenfeld(unweighted_cox,
ph_diagplot_schoenfeld(
unweighted_cox,
time_scale = "month", log_time = TRUE,
endpoint_name = "OS", subtitle = "(Before Matching)"
)
)
expect_equal(original_par, par())

skip_if_not_installed("vdiffr")
vdiffr::expect_doppelganger(
title = "ph_diagplot_schoenfeld",
fig = function() {
ph_diagplot_schoenfeld(
unweighted_cox,
time_scale = "month", log_time = TRUE,
endpoint_name = "OS", subtitle = "(Before Matching)"
)
}
)
})

test_that("kmplot2 works", {
skip_if_not_installed("vdiffr")

data(weighted_twt)
data(adtte_twt)
data(pseudo_ipd_twt)

# plot by trial
expect_warning(
vdiffr::expect_doppelganger(
title = "kmplot2_by_trial",
fig = function() {
kmplot2(
weights_object = weighted_twt,
tte_ipd = adtte_twt,
tte_pseudo_ipd = pseudo_ipd_twt,
trt_ipd = "A",
trt_agd = "B",
trt_common = "C",
trt_var_ipd = "ARM",
trt_var_agd = "ARM",
endpoint_name = "Overall Survival",
km_conf_type = "log-log",
km_layout = "by_trial",
time_scale = "month",
break_x_by = 2
)
}
),
"select_"
)



# plot by arm
vdiffr::expect_doppelganger(
title = "kmplot2_by_am",
fig = function() {
kmplot2(
weights_object = weighted_twt,
tte_ipd = adtte_twt,
tte_pseudo_ipd = pseudo_ipd_twt,
trt_ipd = "A",
trt_agd = "B",
trt_common = "C",
trt_var_ipd = "ARM",
trt_var_agd = "ARM",
endpoint_name = "Overall Survival",
km_conf_type = "log-log",
km_layout = "by_arm",
time_scale = "month",
break_x_by = 2
)
}
)

# plot all
vdiffr::expect_doppelganger(
title = "kmplot2_all",
fig = function() {
kmplot2(
weights_object = weighted_twt,
tte_ipd = adtte_twt,
tte_pseudo_ipd = pseudo_ipd_twt,
trt_ipd = "A",
trt_agd = "B",
trt_common = "C",
trt_var_ipd = "ARM",
trt_var_agd = "ARM",
endpoint_name = "Overall Survival",
km_conf_type = "log-log",
km_layout = "all",
time_scale = "month",
break_x_by = 2,
xlim = c(0, 20),
show_risk_set = FALSE
)
}
)
})

0 comments on commit d398b9b

Please sign in to comment.