teal.modules.clinical
teal.modules.clinical copied to clipboard
Default NA display in tm_t_summary and tm_t_summary_by.
Original Message
This issue was originally reported by Tracy Chang in R User Group chat.
When display NA counts is set to "if any", summaries of numeric values are all missing but categorical values include NA category ("<Missing>"):
<REDACTED>user/118/files/8162fe00-9266-11eb-84ec-19d38dbed475)
When display NA counts is set to "no", numeric values are summarized but it's not possible to show the missing level for categorical variables.
<REDACTED>user/118/files/e28ad180-9266-11eb-9d57-03d32c58911c)
This seems quite restrictive, is there a better way to build the layout to give users more flexibility? Likely users want to always see the numeric summary (even if there are NAs) and would only need to choose whether NA's should be included in the categorical summary.
May also be related to #532.
Sample code:
<REDACTED>NEST/nest_on_bee/master/bee_nest_utils.R")
bee_use_nest(release = "2021_03_22")
library(random.cdisc.data)
library(teal.modules.general)
library(teal.modules.clinical)
adsl <- radsl(cached = T)
adtte <- radtte(
ADSL = adsl,
na_percentage = 0.2,
na_vars = list(AVAL = 1234, EVNTDESC = 1234)
)
app <- teal::init(
data = cdisc_data(
cdisc_dataset("ADSL", adsl),
cdisc_dataset("ADTTE", adtte)
),
modules = root_modules(
modules(
label = "ADTTE",
tm_t_summary_by(
label = "Summary by Visit",
dataname = "ADTTE",
arm_var = choices_selected(c("ARMCD"), "ARMCD"),
by_vars = choices_selected(
choices=variable_choices(adtte[,c("PARAM")]), selected=c("PARAM")),
summarize_vars = choices_selected(variable_choices(adtte[,c("AVAL", "EVNTDESC")]), c("AVAL", "EVNTDESC"))
)
)
)
)
shinyApp(app$ui, app$server)
Provenance:
Creator: anajens
ToDo & Definition of Done
okay, I did some testing and it seems that the "issue" still exists. However, I'm not sure if it's "teal.modules.clinical" should fix this or the upstream teal/teal.modules.general that should take care of this.
original reported issue If display NA is set to "ifany", then numeric summary will have NAs
if display NA is set to "no", then categorical summary will lose the <Missing> category
This actually makes sense to me because we are asking if the user wants to include NA values into your output table or not, and they should be able to filter out the NAs or keep them from the filter panel. However the filter panel is not doing what we expected. It seems that the Keep NA choice applies to all variables, not just he variables interested. If this can be fixed from upstream, I think user will have great flexibility.
BTW, new codes to replicate the error
library(random.cdisc.data)
library(teal.modules.clinical)
adsl <- radsl(cached = T)
adtte <- radtte(
ADSL = adsl,
na_percentage = 0.2,
na_vars = list(AVAL = 1234, EVNTDESC = 1234)
)
app <- init(
data = cdisc_data(
cdisc_dataset("ADSL", adsl),
cdisc_dataset("ADTTE", adtte),
check = FALSE
),
modules = root_modules(
tm_t_summary_by(
label = "Summary by Row Groups Table",
dataname = "ADTTE",
arm_var = choices_selected(
choices = variable_choices(adsl, c("ARM", "ARMCD")),
selected = "ARM"
),
add_total = TRUE,
by_vars = choices_selected(
choices = variable_choices(adtte, c("PARAM")),
selected = c("PARAM")
),
summarize_vars = choices_selected(
choices = variable_choices(adtte, c("AVAL", "EVNTDESC")),
selected = c("AVAL")
),
useNA = "ifany",
paramcd = choices_selected(
choices = value_choices(adtte, "PARAMCD", "PARAM"),
selected = "OS"
)
)
)
)
It seems that ADSL filter is a bit different from other dataset filters where factor variable can display the categories to be included or not. However I'm not sure if I spotted a bug or not.
Maybe it makes sense to drop arm A and arm B as all the ages are NA now? code to reproduce this
library(random.cdisc.data)
library(teal.modules.clinical)
adsl <- radsl(cached = T)
adtte <- radtte(
ADSL = adsl,
na_percentage = 0.2,
na_vars = list(AVAL = 1234, EVNTDESC = 1234)
)
adsl$SEX <- as.character(adsl$SEX)
adsl <- adsl %>% mutate(SEX = ifelse(SEX == "F", "<Missing>", SEX))
adsl$SEX <- as.factor(adsl$SEX)
adsl$RACE <- as.character(adsl$RACE)
adsl <- adsl %>% mutate(RACE = ifelse(RACE == "ASIAN", "<Missing>", RACE))
adsl$RACE <- as.factor(adsl$RACE)
adsl <- adsl %>% mutate(AGE = ifelse(AGE < 65, NA, AGE))
adtte$EVNTDESC <- as.factor(adtte$EVNTDESC)
app <- init(
data = cdisc_data(
cdisc_dataset("ADSL", adsl),
cdisc_dataset("ADTTE", adtte),
check = FALSE
),
modules = root_modules(
tm_t_summary_by(
label = "Summary by Row Groups Table",
dataname = "ADTTE",
arm_var = choices_selected(
choices = variable_choices(adsl, c("ARM", "ARMCD")),
selected = "ARM"
),
add_total = TRUE,
by_vars = choices_selected(
choices = variable_choices(adtte, c("PARAM")),
selected = c("PARAM")
),
summarize_vars = choices_selected(
choices = variable_choices(adtte, c("AVAL", "EVNTDESC")),
selected = c("AVAL")
),
useNA = "ifany",
paramcd = choices_selected(
choices = value_choices(adtte, "PARAMCD", "PARAM"),
selected = "OS"
)
),
tm_t_summary(
label = "ADSL summary",
dataname = "ADSL",
arm_var = choices_selected(c("ARM", "ARMCD"), "ARM"),
add_total = TRUE,
summarize_vars = choices_selected(
c("SEX", "RACE", "BMRKR2", "AGE"),
c("SEX", "RACE")
)
)
)
)
shinyApp(app$ui, app$server)