Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial kmg01_1 #484

Merged
merged 37 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
138bbcd
Initial kmg01_1
Apr 13, 2023
eaea7cd
solve checks
Apr 13, 2023
d146c6e
Update wordlist
Apr 13, 2023
beccf85
Update pkgdown
Apr 13, 2023
00d8804
Add arguments
Apr 13, 2023
4f1faa7
Merge branch 'main' into 373_kmg01_template
Teninq Apr 13, 2023
a554eb4
Add new checks and update document
Apr 13, 2023
68dd797
Add line breaker
Apr 13, 2023
288dc87
Update wordlist
Apr 13, 2023
bfc0720
Merge branch 'main' into 373_kmg01_template
Teninq Apr 19, 2023
e5a4615
Merge branch 'main' into 373_kmg01_template
Teninq Apr 19, 2023
62c5d03
Update comments and documents
Teninq Apr 19, 2023
49bd8fc
Update style
Apr 19, 2023
dc659bb
Update unit test to remove legend position
Apr 19, 2023
02a02bc
Remove library dm
Apr 19, 2023
40ed2de
Merge branch 'main' into 373_kmg01_template
Teninq Apr 19, 2023
973cb48
Update line widths
Apr 19, 2023
2584a65
add aval assertion
Apr 20, 2023
4f5d725
Update with latest dunlin
Apr 20, 2023
a0f4129
Update testthat
Apr 20, 2023
6c384bc
Load dunlin
Apr 20, 2023
7265d98
Update style
Apr 20, 2023
6c9959d
update gitignore
Apr 20, 2023
d862ad2
Update paramcd assertion
Apr 20, 2023
ec876c9
Merge branch '373_kmg01_template' of https://github.com/insightsengin…
Apr 20, 2023
f0c05ba
Update lint code
Apr 20, 2023
a95703b
Update style
Apr 20, 2023
273e7ec
Add assertion to check only one paramcd exists
Apr 20, 2023
1ec7a57
Add missing topic
Apr 20, 2023
3d5cdf1
Add documentation to argument 'param_val'
Apr 20, 2023
547ce12
Update style
Apr 20, 2023
a6111e6
Update style and document
Apr 20, 2023
b9a2e5d
Update comments
Apr 21, 2023
3883ebd
Update style
Apr 21, 2023
efded8a
Update style
Apr 21, 2023
756a8fe
Add check var_arm and is_event
Apr 24, 2023
d85e3de
Remove type hint
Apr 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Collate:
'egt05_qtcat.R'
'ext01.R'
'gen_args.R'
'kmg01.R'
'lbt01.R'
'lbt04.R'
'lbt05.R'
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ export(get_preprocess)
export(gg_list)
export(grob_list)
export(h_format_dec)
export(kmg01_1)
export(kmg01_1_main)
export(kmg01_1_pre)
export(lbt01_1)
export(lbt01_1_lyt)
export(lbt01_1_main)
Expand Down
151 changes: 151 additions & 0 deletions R/kmg01.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# kmg01_1 ----

#' @describeIn kmg01_1 Main TLG Function
#'
#' @details
#' * No overall value.
#'
#' @inheritParams gen_args
#' @param dataset (`string`) the name of a table in the `adam_db` object.
#' @param x_name (`string`) the name of the x-axis.
#' @param y_name (`string`) the name of the x-axis.
#' @param show_statis (`flag`) should the summary statistic table be displayed.
#' @param show_censor (`flag`) should the censor flag be displayed.
#' @param pval_method (`string`) should the censor flag be displayed.
#' @param ties (`string`) should the censor flag be displayed.
#' @param conf_level (`numeric`) should the censor flag be displayed.
#' @param legend_pos (`string`) the position of the legend.
#' @param position_coxph (`numeric`) x and y positions for plotting survival::coxph() model.
#' @param position_surv_med (`numeric`) x and y positions for plotting annotation table estimating
#' median survival time per group.
#' @param line_col (`list`) describing the colors to use for the lines or a named `list` associating values of `arm_var`
#' with color names.
#'
#' @note
#' * `adam_db` object must contain the table specified by `dataset` with the columns specified by `arm_var`.
#'
#' @return a list of `ggplot` objects.
#' @export
kmg01_1_main <- function(adam_db,
dataset = "adtte",
arm_var = "ARM",
x_name = "Time (Days)",
y_name = "Survival Probability",
show_statis = TRUE,
show_censor = TRUE,
pval_method = "wald",
ties = "exact",
conf_level = 0.95,
legend_pos = "bottom",
position_coxph = c(0, 0.05),
position_surv_med = c(0.9, 0.9),
line_col = as.list(nestcolor::color_palette()),
...) {
anl <- adam_db[[dataset]]
checkmate::assert_true(length(unique(anl$PARAMCD)) == 1)
checkmate::assert_character(x_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use assert_string

checkmate::assert_character(y_name)
checkmate::assert_flag(show_statis)
checkmate::assert_flag(show_censor)

line_col <- unlist(line_col)
checkmate::assert_character(line_col, null.ok = TRUE)

variables <- list(tte = "AVAL", is_event = "is_event", arm = arm_var)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not suitable to have "AVAL" and "is_event" fixed here. I would rather expose these two arguments. And, should not we use CNSR here (0 for event and 1 for censor)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it for now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we should check if is_event exists in data

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also arm_var


ggtheme <- ggplot2::theme_bw() +
ggplot2::theme(legend.position = legend_pos)

if (!is.null(names(line_col))) {
color_lvl <- sort(unique(anl[[arm_var]]))
col <- line_col[as.character(color_lvl)]

if (anyNA(col)) {
missing_col <- setdiff(color_lvl, names(col))
stop(paste("Missing color matching for", toString(missing_col)))
}

col <- unname(col)
} else {
col <- line_col
}

gkm_plot <- if (!show_statis) {
g_km(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two parts can be put together

df = anl,
variables = variables,
censor_show = show_censor,
xlab = x_name,
ylab = y_name,
annot_surv_med = TRUE,
control_coxph = control_coxph(pval_method = pval_method, ties = ties, conf_level = conf_level),
ggtheme = ggtheme,
position_coxph = position_coxph,
position_surv_med = position_surv_med
)
} else {
g_km(
df = anl,
variables = variables,
censor_show = show_censor,
xlab = x_name,
ylab = y_name,
annot_coxph = TRUE,
control_coxph = control_coxph(pval_method = pval_method, ties = ties, conf_level = conf_level),
ggtheme = ggtheme,
position_coxph = position_coxph,
position_surv_med = position_surv_med
)
}
}

#' @describeIn kmg01_1 Preprocessing
#'
#' @inheritParams kmg01_1_main
#' @param paramcd (`string`) PARAMCD of the endpoint need to be analysis
#'
#' @export
kmg01_1_pre <- function(adam_db, dataset, paramcd = "OS", ...) {
checkmate::assert_class(adam_db, "dm")
assert_colnames(adam_db[[dataset]], c("PARAMCD", "CNSR"))

adam_db <- adam_db %>%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use list of data frames

dm_zoom_to(!!dataset) %>%
filter(.data$PARAMCD == paramcd) %>%
mutate(is_event = CNSR == 0) %>%
dm_update_zoomed()
}

#' @describeIn kmg01_1 Postprocessing
#'
#' @inheritParams gen_args
#'
kmg01_1_post <- function(tlg, ...) {
tlg
}

# `kmg01_1` Pipeline ----

#' `KMG01` Kaplan-Meier Plot 1.
#'
#'
#' @include chevron_tlg-S4class.R
#' @export
#'
#' @examples
#' library(dm)
#' library(dplyr)
#'
#' col <- c(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make it consistent with the argument passing from citril, we have to make it either a named list or unnamed character

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed with list()

#' "A: Drug X" = "black",
#' "B: Placebo" = "blue",
#' "C: Combination" = "gray"
#' )
#'
#' run(kmg01_1, syn_data, dataset = "adtte", line_col = col)
kmg01_1 <- chevron_g(
main = kmg01_1_main,
preproces = kmg01_1_pre,
postprocess = kmg01_1_post,
adam_datasets = c("adsl", "adtte")
)
1 change: 1 addition & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ reference:
- egt05_qtcat_1
- ext01_1
- ext01_2
- kmg01_1
- lbt01_1
- lbt04_1
- lbt05_1
Expand Down
13 changes: 6 additions & 7 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ ADEG
ADaM
AESI
CTCAE
gg
gg_list
Hoffmann
Kaplan
NCI
PARAMCD
Postprocessing
postprocessing
preprocess
Pre
Repo
SSO
Rua
TLG
TLGs
coxph
de
funder
postprocessing
pre
preprocess
repo
reproducibility
de
Rua
112 changes: 112 additions & 0 deletions man/kmg01_1.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions tests/testthat/_snaps/default_tlg.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,25 @@
Grade 3-4 43 (32.1%) 46 (34.3%) 43 (32.6%)
4 43 (32.1%) 46 (34.3%) 43 (32.6%)

# aet10_1 functions with default argument value return expected result with test data

Code
res
Output
A: Drug X B: Placebo C: Combination
MedDRA Preferred Term (N=134) (N=134) (N=132)
————————————————————————————————————————————————————————————————
dcd D.2.1.5.3 47 (35.1%) 58 (43.3%) 57 (43.2%)
dcd A.1.1.1.1 50 (37.3%) 45 (33.6%) 63 (47.7%)
dcd B.2.2.3.1 48 (35.8%) 54 (40.3%) 51 (38.6%)
dcd A.1.1.1.2 48 (35.8%) 48 (35.8%) 50 (37.9%)
dcd B.2.1.2.1 49 (36.6%) 44 (32.8%) 52 (39.4%)
dcd D.1.1.1.1 50 (37.3%) 42 (31.3%) 51 (38.6%)
dcd D.1.1.4.2 48 (35.8%) 42 (31.3%) 50 (37.9%)
dcd B.1.1.1.1 47 (35.1%) 49 (36.6%) 43 (32.6%)
dcd C.2.1.2.1 35 (26.1%) 48 (35.8%) 55 (41.7%)
dcd C.1.1.1.3 43 (32.1%) 46 (34.3%) 43 (32.6%)

# cmt01a_1 functions with default argument value return expected result with test data

Code
Expand Down
25 changes: 25 additions & 0 deletions tests/testthat/test-kmg01.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
test_that("kmg01_1 works as expected", {
pre_data <- expect_silent(kmg01_1_pre(syn_data, dataset = "adtte"))
raw_res <- expect_silent(kmg01_1_main(pre_data, dataset = "adtte"))
checkmate::assert_true(grid::is.grob(raw_res))
})



test_that("kmg01_1 works as expected with custom color set", {
col <- list(
"A: Drug X" = "black",
"B: Placebo" = "blue",
"C: Combination" = "gray"
)

res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", line_col = col))
checkmate::assert_true(grid::is.grob(res))
res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", line_col = unname(col)))
checkmate::assert_true(grid::is.grob(res))
})

test_that("kmg01_1 works if show_statis/show_censor is FALSE", {
res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", show_statis = FALSE, show_censor = FALSE))
checkmate::assert_true(grid::is.grob(res))
})