Skip to content

Commit e5f45ab

Browse files
committed
clarify interpretation in shiny app
1 parent f5981cd commit e5f45ab

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

inst/app/modules/mod_designsummary.R

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,56 @@ mod_designsummary_server <- function(
6464
}
6565

6666
decision_txt <- if (identical(vals$mode, "gamma")) {
67-
sprintf(
68-
"Success if \\(\\Pr({\\theta}_t - {\\theta}_c > %s)\\ \\ge\\ %s\\).",
69-
mjax_pct(vals$M, 0), mjax_pct(vals$gamma, 0)
67+
paste0(
68+
"<p><strong>Trial-level decision rule:</strong></p>",
69+
"<ul>",
70+
"<li>For a given simulated dataset, ",
71+
"\\(Pr(\\theta_t - \\theta_c > ", mjax_pct(vals$M, 0), ")\\) ",
72+
"is calculated from ", fmt_int(vals$ndraws), " posterior draws.</li>",
73+
"<li>The null hypothesis \\(H_0\\) is rejected if this probability ",
74+
"exceeds \\(\\gamma = ", mjax_pct(vals$gamma, 0), "\\).</li>",
75+
"</ul>"
7076
)
7177
} else {
72-
target <- switch(vals$calibrate_on,
73-
point = "the MC point estimate of Type-I error",
74-
upper = "the upper bound of the 95\\% MC CI for the Type-I error",
75-
lower = "the lower bound of the 95\\% MC CI for the Type-I error"
78+
target <- switch(
79+
vals$calibrate_on,
80+
point = "the MC point estimate of Type-I error",
81+
upper = "the upper bound of the 95\\% MC CI for the Type-I error",
82+
lower = "the lower bound of the 95\\% MC CI for the Type-I error"
7683
)
77-
sprintf(
78-
"Posterior threshold \\(\\gamma\\) will be calibrated so that %s \\(\\approx\\) \\(\\alpha = %s\\) at the least-favourable null.",
79-
target, mjax_pct(vals$alpha, 0)
84+
paste0(
85+
"<p><strong>Trial-level decision rule:</strong></p>",
86+
"<ul>",
87+
"<li>The posterior threshold \\(\\gamma\\) is calibrated so that ",
88+
target, " \\(\\approx \\alpha = ", mjax_pct(vals$alpha, 0), "\\).</li>",
89+
"<li>For a given simulated dataset, probabilities are calculated ",
90+
"from ", fmt_int(vals$ndraws), " posterior draws.</li>",
91+
"</ul>"
8092
)
8193
}
8294

83-
sim_txt <- sprintf(
84-
"Planned Monte Carlo: %s trials (B) and %s posterior draws per trial; seed = %s.",
85-
fmt_int(vals$B), fmt_int(vals$ndraws), vals$seed
95+
sim_txt <- paste0(
96+
"<p><strong>Simulation setup:</strong></p>",
97+
"<ul>",
98+
"<li><b>Type-I error:</b> The trial-level decision rule is repeated ",
99+
fmt_int(vals$B), " times using datasets simulated under the least-favourable null.</li>",
100+
"<li><b>Power:</b> The same procedure is repeated ",
101+
fmt_int(vals$B), " times using datasets simulated under the assumed truths.</li>",
102+
"<li>Random seed = ", vals$seed, ".</li>",
103+
"</ul>"
86104
)
87105

88106
# ---------------- NEW: Likelihood & Prior with configured numbers ----------------
89107
n_t <- vals$nt; n_c <- vals$nc
108+
109+
dgm_eq <- paste0(
110+
"\\[\\begin{aligned}\n",
111+
"y_t &\\sim \\mathrm{Binomial}(", n_t, ",\\,", fmt_dec(vals$pt, 2), ") \\\\\n",
112+
"y_c &\\sim \\mathrm{Binomial}(", n_c, ",\\,", fmt_dec(vals$pc, 2), ")\n",
113+
"\\end{aligned}\\]"
114+
)
115+
116+
90117
lik_eq <- paste0(
91118
"\\[\\begin{aligned}\n",
92119
"y_t\\mid\\theta_t &\\sim \\mathrm{Binomial}(", n_t, ",\\,\\theta_t)\\\\\n",
@@ -127,19 +154,14 @@ mod_designsummary_server <- function(
127154
html <- paste0(
128155
"<details open><summary><h4>Design summary</h4></summary><div>",
129156
"<h5>Data-generating assumptions</h5>",
130-
"<ul>",
131-
"<li><b>Truths:</b> \\(\\theta_t = ", mjax_pct(vals$pt,0),
132-
"\\), \\(\\theta_c = ", mjax_pct(vals$pc,0), "\\)</li>",
133-
"<li><b>Sample sizes:</b> treatment \\(n_t = ", vals$nt,
134-
"\\), control \\(n_c = ", vals$nc, "\\)</li>",
135-
"</ul>",
157+
dgm_eq,
136158

137159
"<h5>Analysis model (likelihood & prior)</h5>",
138160
lik_eq, prior_eq,
139161

140-
"<h5>Decision rule</h5><p>", decision_txt, "</p>",
162+
decision_txt,
141163

142-
"<h5>Simulation setup</h5><p>", sim_txt, "</p>",
164+
sim_txt,
143165
"</div>",
144166
"</details>"
145167
)

tests/testthat/test-ssre.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require(rjags)
2-
31
test_that("Test sample size re-estimation at interim", {
42
nsim <- 10000
53
alpha <- 0.05

0 commit comments

Comments
 (0)