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

681 Add titles/footnotes for tm_a_gee #691

Merged
merged 8 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

### Enhancements
* Replaced `synthetic_cdisc_data` with refactored `synthetic_cdisc_dataset` function to speed up dataset loading in tests/examples.
* Added titles and footnotes to `tm_a_gee`.

### Miscellaneous
* Package now uses `scda.2022` rather than `scda.2021` in SUGGESTS.
Expand Down
114 changes: 109 additions & 5 deletions R/tm_a_gee.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ template_a_gee <- function(output_table,
visit_var,
split_covariates,
cor_struct,
conf_level = 0.95) {
conf_level = 0.95,
basic_table_args = teal.widgets::basic_table_args()) {
y <- list()
y$model <- list()
y$table <- list()

all_basic_table_args <- teal.widgets::resolve_basic_table_args(basic_table_args)

model_list <- add_expr(
list(),
substitute(
Expand Down Expand Up @@ -59,14 +62,28 @@ template_a_gee <- function(output_table,
add_expr(
list(),
if (output_table == "t_gee_cov") {
quote(result_table <- tern.gee::as.rtable(model_fit, type = "cov"))
substitute(
expr = {
result_table <- tern.gee::as.rtable(model_fit, type = "cov")
subtitles(result_table) <- st
main_footer(result_table) <- mf
},
env = list(
st = basic_table_args$subtitles,
mf = basic_table_args$main_footer
)
)
} else if (output_table == "t_gee_coef") {
substitute(
expr = {
result_table <- tern.gee::as.rtable(model_fit, type = "coef", conf_level = conf_level)
subtitles(result_table) <- st
main_footer(result_table) <- mf
},
env = list(
conf_level = conf_level
conf_level = conf_level,
st = basic_table_args$subtitles,
mf = basic_table_args$main_footer
)
)
} else if (output_table == "t_gee_lsmeans") {
Expand All @@ -82,12 +99,16 @@ template_a_gee <- function(output_table,
alt_counts_df = dataname_lsmeans
)

subtitles(result_table) <- st
main_footer(result_table) <- mf
result_table
},
env = list(
dataname_lsmeans = as.name(dataname_lsmeans),
conf_level = conf_level,
input_arm_var = input_arm_var
input_arm_var = input_arm_var,
st = basic_table_args$subtitles,
mf = basic_table_args$main_footer
)
)
}
Expand All @@ -107,6 +128,60 @@ template_a_gee <- function(output_table,
#' @export
#'
#' @examples
#' library(scda)
#'
#' ADSL <- synthetic_cdisc_dataset("latest", "adsl")
#' ADQS <- synthetic_cdisc_dataset("latest", "adqs") %>%
#' dplyr::filter(ABLFL != "Y" & ABLFL2 != "Y") %>%
#' dplyr::mutate(
#' AVISIT = as.factor(AVISIT),
#' AVISITN = rank(AVISITN) %>%
#' as.factor() %>%
#' as.numeric() %>%
#' as.factor(),
#' AVALBIN = AVAL < 50 # Just as an example to get a binary endpoint.
#' ) %>%
#' droplevels()
#'
#' app <- init(
#' data = cdisc_data(
#' cdisc_dataset("ADSL", ADSL,
#' code = 'synthetic_cdisc_dataset("latest", "adsl")'
#' ),
#' cdisc_dataset("ADQS", ADQS,
#' code = 'ADQS <- synthetic_cdisc_dataset("latest", "adqs") %>%
#' dplyr::filter(ABLFL != "Y" & ABLFL2 != "Y") %>%
#' dplyr::mutate(
#' AVISIT = as.factor(AVISIT),
#' AVISITN = rank(AVISITN) %>%
#' as.factor() %>%
#' as.numeric() %>%
#' as.factor(),
#' AVALBIN = AVAL < 50 # Just as an example to get a binary endpoint.
#' ) %>%
#' droplevels()'
#' )
#' ),
#' modules = modules(
#' tm_a_gee(
#' label = "GEE",
#' dataname = "ADQS",
#' aval_var = choices_selected("AVALBIN", fixed = TRUE),
#' id_var = choices_selected(c("USUBJID", "SUBJID"), "USUBJID"),
#' arm_var = choices_selected(c("ARM", "ARMCD"), "ARM"),
#' visit_var = choices_selected(c("AVISIT", "AVISITN"), "AVISIT"),
#' paramcd = choices_selected(
#' choices = value_choices(ADQS, "PARAMCD", "PARAM"),
#' selected = "FKSI-FWB"
#' ),
#' cov_var = choices_selected(c("BASE", "AGE", "SEX"), NULL)
#' )
#' )
#' )
#' if (interactive()) {
#' shiny::shinyApp(app$ui, app$server)
#' }
#'
tm_a_gee <- function(label,
dataname,
parentname = ifelse(
Expand Down Expand Up @@ -183,6 +258,7 @@ ui_gee <- function(id, ...) {

teal.widgets::standard_layout(
output = teal.widgets::white_small_well(
shiny::h3(shiny::textOutput(ns("gee_title"))),
teal.widgets::table_with_settings_ui(ns("table"))
),
encoding = shiny::div(
Expand Down Expand Up @@ -378,16 +454,30 @@ srv_gee <- function(id,
adsl_input_r = adsl_inputs,
anl_q = anl_q
)

# Initially hide the output title because there is no output yet.
shinyjs::show("gee_title")

# To do in production: add validations.

## table_r ----
table_q <- shiny::reactive({
output_table <- input$output_table
conf_level <- as.numeric(input$conf_level)
col_source <- merged$anl_input_r()$columns_source
filter_info <- merged$anl_input_r()$filter_info

req(output_table)

basic_table_args$subtitles <- paste0(
"Analysis Variable: ", col_source$aval_var,
", Endpoint: ", filter_info$paramcd[[1]]$selected[[1]],
Comment on lines +473 to +474
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use the variable label instead of the variable name in the title to be more descriptive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if this is necessary since the subtitles are mainly just to track input values when creating report cards. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @Melkiades and @juliadedic1 I thought I would loop you in for your opinion on this as I am not entirely sure. I was wondering what you guys think.

Choose a reason for hiding this comment

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

@Nolan-Steed what would be your proposed alternative in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

@juliadedic1 I was thinking of grabbing the variable label instead of the variable name in the subtitle.

ifelse(length(col_source$split_covariates) == 0, "",
paste(", Covariates:", paste(col_source$split_covariates, collapse = ", "))
)
)
basic_table_args$main_footer <- c(paste("Correlation Structure:", input$cor_struct))

my_calls <- template_a_gee(
output_table = output_table,
data_model_fit = "ANL",
Expand All @@ -399,11 +489,25 @@ srv_gee <- function(id,
id_var = col_source$id_var,
arm_var = col_source$arm_var,
visit_var = col_source$visit_var,
cor_struct = input$cor_struct
cor_struct = input$cor_struct,
basic_table_args = basic_table_args
)
teal.code::eval_code(merged$anl_q(), as.expression(my_calls))
})

output$gee_title <- shiny::renderText({
# Input on output type.
output_table <- input$output_table

output_title <- switch(
output_table,
"t_gee_cov" = "Residual Covariance Matrix Estimate",
"t_gee_coef" = "Model Coefficients",
"t_gee_lsmeans" = "LS Means Estimates"
edelarua marked this conversation as resolved.
Show resolved Hide resolved
)
output_title
})

table_r <- shiny::reactive({
table_q()[["result_table"]]
})
Expand Down
10 changes: 9 additions & 1 deletion man/template_a_gee.Rd

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

56 changes: 56 additions & 0 deletions man/tm_a_gee.Rd

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