Skip to content

Commit

Permalink
Merge pull request #151 from OHDSI/add_impute_missings
Browse files Browse the repository at this point in the history
Add impute missings option in the shiny
  • Loading branch information
edward-burn authored Dec 4, 2024
2 parents 20fca6f + da706db commit 4e393f4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
8 changes: 7 additions & 1 deletion inst/shiny/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ if(file.exists(here::here("data", "appData.RData"))){
cli::cli_alert_success("Data processed")
}

plotComparedLsc <- function(lsc, cohorts, colour = NULL, facet = NULL){
plotComparedLsc <- function(lsc, cohorts, imputeMissings, colour = NULL, facet = NULL){
lsc <- lsc |> tidy()

plot_data <- lsc |>
filter(cohort_name %in% c(cohorts
)) |>
Expand All @@ -54,6 +55,11 @@ plotComparedLsc <- function(lsc, cohorts, colour = NULL, facet = NULL){
pivot_wider(names_from = cohort_name,
values_from = percentage)

if(isTRUE(imputeMissings)){
plot_data <- plot_data |>
mutate(across(c(cohorts[1], cohorts[2]), ~if_else(is.na(.x), 0, .x)))
}

plot <- plot_data |>
ggplot(aes(text = paste("<br>Database:", database,
"<br>Concept:", variable_name,
Expand Down
2 changes: 1 addition & 1 deletion inst/shiny/scripts/preprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ selected$compare_large_scale_characteristics_grouping_domain <- choices$compare_
if(!is.null(dataFiltered$summarise_large_scale_characteristics)){
if(nrow(dataFiltered$summarise_large_scale_characteristics)>0){
choices$summarise_large_scale_characteristics_grouping_domain <- settings(dataFiltered$summarise_large_scale_characteristics) |>
pull("table_name")
pull("table_name") |> unique()
selected$summarise_large_scale_characteristics_grouping_domain <- choices$summarise_large_scale_characteristics_grouping_domain
}}

Expand Down
10 changes: 8 additions & 2 deletions inst/shiny/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ server <- function(input, output, session) {

output$gt_compare_lsc <- DT::renderDT({
lscFiltered <- outputLSC()

if (nrow(lscFiltered) == 0) {
validate("No results found for selected inputs")
}
Expand All @@ -1095,6 +1095,11 @@ server <- function(input, output, session) {
pivot_wider(names_from = cohort_name,
values_from = percentage)

if(isTRUE(input$compare_large_scale_characteristics_impute_missings)){
lsc <- lsc |>
mutate(across(c(target_cohort, comparator_cohort), ~if_else(is.na(.x), 0, .x)))
}

lsc <-lsc |>
mutate(across(c(target_cohort, comparator_cohort), ~ as.numeric(.x)/100)) |>
mutate(smd = (!!sym(target_cohort) - !!sym(comparator_cohort))/sqrt((!!sym(target_cohort)*(1-!!sym(target_cohort)) + !!sym(comparator_cohort)*(1-!!sym(comparator_cohort)))/2)) |>
Expand Down Expand Up @@ -1128,7 +1133,8 @@ server <- function(input, output, session) {
cohorts = c(input$compare_large_scale_characteristics_grouping_cohort_1,
input$compare_large_scale_characteristics_grouping_cohort_2),
colour = c(input$compare_large_scale_characteristics_colour_1),
facet = c(input$compare_large_scale_characteristics_facet_1)
facet = c(input$compare_large_scale_characteristics_facet_1),
imputeMissings = input$compare_large_scale_characteristics_impute_missings
)
})

Expand Down
6 changes: 5 additions & 1 deletion inst/shiny/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,11 @@ ui <- bslib::page_navbar(
selected = NULL,
multiple = TRUE,
options = list(`actions-box` = TRUE, size = 10, `selected-text-format` = "count > 3")
)
),
shinyWidgets::prettyCheckbox(
inputId = "compare_large_scale_characteristics_impute_missings",
label = "Impute missing values as 0",
value = FALSE)
)
)
),
Expand Down

0 comments on commit 4e393f4

Please sign in to comment.