Skip to content

Commit c87b4d9

Browse files
committed
Omit irrelevant fields from the app
1 parent ce2e114 commit c87b4d9

File tree

1 file changed

+45
-56
lines changed

1 file changed

+45
-56
lines changed

inst/app/app.R

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,6 @@ ui <- navbarPage(
194194
),
195195

196196
sat_decision_criteria_ui("crit_sa"),
197-
198-
199-
200-
numericInput("B_sa", "Number of simulations", value = 1000, min = 100, step = 100),
201-
numericInput("ndraws_sa", "Posterior draws per simulation", value = 2000, min = 500, step = 100),
202-
numericInput("seed_sa", "Random seed (optional)", value = 123, min = 1, step = 1),
203-
204-
actionButton("run_sa", "Run single-arm simulation", class = "btn-primary")
205197
),
206198

207199
mainPanel(
@@ -383,7 +375,7 @@ server <- function(input, output, session) {
383375
pc_current = reactive(input$pc) # for pre-filling the range nicely
384376
)
385377

386-
observeEvent(input$run_sa, {
378+
sa_results <- reactive({
387379
req(input$pt_sa, input$nt_sa,
388380
input[["crit_sa-M_sa"]],
389381
input[["crit_sa-gamma_sa"]])
@@ -400,56 +392,53 @@ server <- function(input, output, session) {
400392
M <- input[["crit_sa-M_sa"]] / 100
401393
gamma <- input[["crit_sa-gamma_sa"]] / 100
402394

403-
withProgress(message = "Running single-arm simulations...", {
404-
power_res <- bcts::singlearm_beta_power(
405-
B = B,
406-
p_t = pt,
407-
n_t = input$nt_sa,
408-
M = M,
409-
threshold = gamma,
410-
prior = prior_type,
411-
a_base = a_base,
412-
b_base = b_base,
413-
#n_draws = n_draws,
414-
method = "exact",
415-
show_progress = FALSE
416-
)
417-
418-
type1_res <- bcts::singlearm_beta_type1(
419-
B = B,
420-
n_t = input$nt_sa,
421-
M = M,
422-
threshold = gamma,
423-
prior = prior_type,
424-
a_base = a_base,
425-
b_base = b_base,
426-
n_draws = n_draws,
427-
show_progress = FALSE
428-
)
395+
power_res <- bcts::singlearm_beta_power(
396+
B = B,
397+
p_t = pt,
398+
n_t = input$nt_sa,
399+
M = M,
400+
threshold = gamma,
401+
prior = prior_type,
402+
a_base = a_base,
403+
b_base = b_base,
404+
method = "exact",
405+
show_progress = FALSE
406+
)
429407

430-
output$sa_summary <- renderPrint({
431-
cat("POWER ANALYSIS\n")
432-
cat(sprintf("Estimated power: %.2f%%\n", 100 * power_res$estimate))
433-
cat(sprintf("MC standard error: %.2f%%\n", 100 * power_res$mc_se))
434-
cat(sprintf("Successes: %d out of %d simulations\n\n", power_res$successes, power_res$B))
408+
type1_res <- bcts::singlearm_beta_type1(
409+
B = B,
410+
n_t = input$nt_sa,
411+
M = M,
412+
threshold = gamma,
413+
prior = prior_type,
414+
a_base = a_base,
415+
b_base = b_base,
416+
n_draws = n_draws,
417+
method = "exact",
418+
show_progress = FALSE
419+
)
435420

436-
cat("TYPE-I ERROR ANALYSIS\n")
437-
cat(sprintf("Estimated Type-I error: %.2f%%\n", 100 * type1_res$estimate))
438-
cat(sprintf("MC standard error: %.2f%%\n", 100 * type1_res$mc_se))
439-
cat(sprintf("False positives: %d out of %d simulations\n", type1_res$successes, type1_res$B))
440-
})
421+
list(power = power_res, type1 = type1_res)
422+
})
441423

442-
output$sa_power_plot <- renderPlot({
443-
barplot(
444-
height = c(100 * power_res$estimate, 100 * type1_res$estimate),
445-
names.arg = c("Power", "Type-I error"),
446-
ylim = c(0, 100),
447-
col = c("#4682B4", "#D2691E"),
448-
ylab = "Estimate (%)",
449-
main = "Single-Arm Trial: Power vs Type-I Error"
450-
)
451-
})
452-
})
424+
output$sa_summary <- renderPrint({
425+
res <- sa_results()
426+
power_res <- res$power
427+
type1_res <- res$type1
428+
429+
cat("POWER ANALYSIS\n")
430+
cat(sprintf("Estimated power: %.2f%%\n", 100 * power_res$estimate))
431+
cat(sprintf("MC standard error: %.2f%%\n", 100 * power_res$mc_se %||% NA_real_))
432+
cat(sprintf("Successes: %d out of %d simulations\n\n",
433+
power_res$successes %||% NA_integer_,
434+
power_res$B %||% NA_integer_))
435+
436+
cat("TYPE-I ERROR ANALYSIS\n")
437+
cat(sprintf("Estimated Type-I error: %.2f%%\n", 100 * type1_res$estimate))
438+
cat(sprintf("MC standard error: %.2f%%\n", 100 * type1_res$mc_se %||% NA_real_))
439+
cat(sprintf("False positives: %d out of %d simulations\n",
440+
type1_res$successes %||% NA_integer_,
441+
type1_res$B %||% NA_integer_))
453442
})
454443

455444
}

0 commit comments

Comments
 (0)