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 35 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
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
.RData
.Ruserdata
.DS_Store
InputVads.Rdata
t_ae_ctc_SE.out
t_ae_ctc_ATEZOREL_SENBX.out
inst/doc
docs
temp
*.bak
.Renviron
.Rprofile
.vscode
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Collate:
'egt05_qtcat.R'
'ext01.R'
'gen_args.R'
'kmg01.R'
'lbt01.R'
'lbt04.R'
'lbt05.R'
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export(aet10_1_pre)
export(args_ls)
export(assert_all_tablenames)
export(assert_colnames)
export(assert_only_one_paramcd)
export(chevron_g)
export(chevron_l)
export(chevron_t)
Expand Down Expand Up @@ -150,6 +151,10 @@ export(get_preprocess)
export(gg_list)
export(grob_list)
export(h_format_dec)
export(kmg01_1)
export(kmg01_1_main)
export(kmg01_1_post)
export(kmg01_1_pre)
export(lbt01_1)
export(lbt01_1_lyt)
export(lbt01_1_main)
Expand Down
4 changes: 3 additions & 1 deletion R/ael01_nollt.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ ael01_nollt_1_post <- function(tlg, ...) {
#' @export
#'
#' @examples
#' run(ael01_nollt_1, syn_data, new_lbls = list(AETERM = "Investigator-Specified\n Adverse Event Term"))
#' run(ael01_nollt_1, syn_data, new_lbls = list(
#' AETERM = "Investigator-Specified\n Adverse Event Term"
#' ))
ael01_nollt_1 <- chevron_l(
main = ael01_nollt_1_main,
preprocess = ael01_nollt_1_pre,
Expand Down
15 changes: 15 additions & 0 deletions R/assertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,18 @@ assert_subset_suggest <- function(x, choices) {

stop(msg, call. = FALSE)
}


#' Check to have only one PARAMCD in the analysis dataset
#' @param param_val (`character`) value of PARAMCD
Copy link
Contributor

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

#' @export
assert_only_one_paramcd <- function(param_val) {
unique_param_val <- unique(param_val)
if (length(unique_param_val) > 1) {
stop(paste0(
"More than one parameters:",
toString(unique_param_val),
", only one suppose to have."
))
}
}
137 changes: 137 additions & 0 deletions R/kmg01.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",
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)
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



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, ...) {
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")
#' 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")
)
2 changes: 2 additions & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ reference:
- egt05_qtcat_1
- ext01_1
- ext01_2
- kmg01_1
- lbt01_1
- lbt04_1
- lbt05_1
Expand Down Expand Up @@ -108,6 +109,7 @@ reference:
- h_format_dec
- gg_list
- grob_list
- assert_only_one_paramcd

- title: Non-exported Documented Functions for Packagage Developers
contents:
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
4 changes: 3 additions & 1 deletion man/ael01_nollt_1.Rd

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

14 changes: 14 additions & 0 deletions man/assert_only_one_paramcd.Rd

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

111 changes: 111 additions & 0 deletions man/kmg01_1.Rd

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

Loading