-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Initial kmg01_1 #484
Changes from 35 commits
138bbcd
eaea7cd
d146c6e
beccf85
00d8804
4f1faa7
a554eb4
68dd797
288dc87
bfc0720
e5a4615
62c5d03
49bd8fc
dc659bb
02a02bc
40ed2de
973cb48
2584a65
4f5d725
a0f4129
6c384bc
7265d98
6c9959d
d862ad2
ec876c9
f0c05ba
a95703b
273e7ec
1ec7a57
3d5cdf1
547ce12
a6111e6
b9a2e5d
3883ebd
efded8a
756a8fe
d85e3de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ Collate: | |
'egt05_qtcat.R' | ||
'ext01.R' | ||
'gen_args.R' | ||
'kmg01.R' | ||
'lbt01.R' | ||
'lbt04.R' | ||
'lbt05.R' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# 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 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", | ||
clarkliming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
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]] | ||
assert_colnames(anl, "PARAMCD") | ||
assert_only_one_paramcd(anl$PARAMCD) | ||
checkmate::assert_string(x_name) | ||
checkmate::assert_string(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) | ||
|
||
assert_colnames(anl, "AVAL") | ||
variables <- list(tte = "AVAL", is_event = "is_event", arm = arm_var) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep it for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but we should check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and also arm_var |
||
|
||
|
||
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 | ||
} | ||
|
||
g_km( | ||
df = anl, | ||
variables = variables, | ||
censor_show = show_censor, | ||
xlab = x_name, | ||
ylab = y_name, | ||
annot_surv_med = !show_statis, | ||
annot_coxph = show_statis, | ||
control_coxph_pw = control_coxph(pval_method = pval_method, ties = ties, conf_level = conf_level), | ||
position_coxph = position_coxph, | ||
position_surv_med = position_surv_med | ||
) | ||
} | ||
|
||
#' @describeIn kmg01_1 Preprocessing | ||
#' | ||
#' @inheritParams kmg01_1_main | ||
#' | ||
#' @export | ||
kmg01_1_pre <- function(adam_db, dataset = "adtte", ...) { | ||
assert_all_tablenames(adam_db, c("adsl", dataset)) | ||
assert_colnames(adam_db[[dataset]], "CNSR") | ||
|
||
adam_db[[dataset]] <- adam_db[[dataset]] %>% | ||
mutate(is_event = .data$CNSR == 0) | ||
|
||
adam_db | ||
} | ||
|
||
#' @describeIn kmg01_1 Postprocessing | ||
#' | ||
#' @inheritParams gen_args | ||
#' | ||
#' @export | ||
kmg01_1_post <- function(tlg, ...) { | ||
clarkliming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tlg | ||
} | ||
|
||
# `kmg01_1` Pipeline ---- | ||
|
||
#' `KMG01` Kaplan-Meier Plot 1. | ||
#' | ||
#' | ||
#' @include chevron_tlg-S4class.R | ||
#' @export | ||
#' | ||
#' @examples | ||
#' library(dplyr) | ||
#' library(dunlin) | ||
#' | ||
#' col <- list( | ||
#' "A: Drug X" = "black", | ||
#' "B: Placebo" = "blue", | ||
#' "C: Combination" = "gray" | ||
#' ) | ||
#' | ||
#' syn_data2 <- log_filter(syn_data, PARAMCD == "OS", "adtte") | ||
clarkliming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#' run(kmg01_1, syn_data2, dataset = "adtte", line_col = col) | ||
#' | ||
#' syn_data3 <- log_filter(syn_data, PARAMCD == "AEREPTTE", "adaette") | ||
#' run(kmg01_1, syn_data3, dataset = "adaette") | ||
kmg01_1 <- chevron_g( | ||
main = kmg01_1_main, | ||
preproces = kmg01_1_pre, | ||
postprocess = kmg01_1_post, | ||
adam_datasets = c("adsl") | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we don't require it to be a character (as factor also works), remove the type hint or at least check if it is character or factor, and correct the type hint