This vignette shows the functions
that help to plan a proof-of-concept study and to explain its decision:
scenarios for the operating characteristics
(qdm_scenarios()), the comparison of designs
(qdm_compare()), the search for the sample size
(qdm_find_n()), tables of results
(as.data.frame()), the plot of a decision and the R code of
a design (show_code()). The examples use one binary
endpoint, and the functions work in the same way for the other
endpoints.
des <- design_binary(
n_t = 12, n_c = 12,
prior_t = prior_beta(0.5, 0.5), prior_c = prior_beta(0.5, 0.5),
criterion = criterion_posterior(theta_tv = 0.2, theta_mav = 0.1,
gamma_go = 0.5, gamma_nogo = 0.8)
)qdm_scenarios() creates the data frame of scenarios with
the columns that the design needs (see qdm_oc()), and a
missing or misspelled column is an error. By default it takes all
combinations of the values:
qdm_scenarios(des, pi_t = c(0.3, 0.5), pi_c = c(0.2, 0.3))
#> pi_t pi_c
#> 1 0.3 0.2
#> 2 0.5 0.2
#> 3 0.3 0.3
#> 4 0.5 0.3The scenarios can also be given by the treatment effect
theta and the control group, which is convenient for two
endpoints and for a time-to-event endpoint, whose scenarios are median
survival times. With theta = "thresholds", the scenarios
are those that a protocol usually reports: no effect, the minimum
acceptable value (MAV) and the target value (TV).
scen <- qdm_scenarios(des, theta = seq(0, 0.4, by = 0.1), pi_c = 0.3)
scen
#> theta pi_t pi_c
#> 1 0.0 0.3 0.3
#> 2 0.1 0.4 0.3
#> 3 0.2 0.5 0.3
#> 4 0.3 0.6 0.3
#> 5 0.4 0.7 0.3
qdm_oc(des, qdm_scenarios(des, theta = "thresholds", pi_c = 0.3))
#> Operating characteristics (exact enumeration of the outcomes)
#> theta pi_t pi_c Go NoGo Gray Miss
#> 0.0 0.3 0.3 0.1316 0.4170 0.4514 0
#> 0.1 0.4 0.3 0.2893 0.2325 0.4782 0
#> 0.2 0.5 0.3 0.4883 0.1094 0.4023 0For a continuous endpoint, sd gives the same standard
deviation to both groups, and sd1, sd2 and
rho do the same for two continuous endpoints.
The design steps (see vignette("pipe")) accept a design,
so designs that differ in one part are made from des.
qdm_compare() computes their operating characteristics
under the same scenarios, in one table with a column that names the
design:
n <- c(12, 18, 24)
designs <- lapply(n, function(k) qdm_sample_size(des, n_t = k, n_c = k))
names(designs) <- paste(n, "per group")
cmp <- qdm_compare(designs, scen)
cmp
#> Operating characteristics of 3 designs
#> Method: exact enumeration of the outcomes
#> design theta pi_t pi_c Go NoGo Gray Miss
#> 12 per group 0.0 0.3 0.3 0.13165 0.416956 0.45139 0
#> 12 per group 0.1 0.4 0.3 0.28929 0.232488 0.47822 0
#> 12 per group 0.2 0.5 0.3 0.48831 0.109372 0.40232 0
#> 12 per group 0.3 0.6 0.3 0.68750 0.041368 0.27113 0
#> 12 per group 0.4 0.7 0.3 0.84722 0.011504 0.14128 0
#> 18 per group 0.0 0.3 0.3 0.10072 0.430011 0.46927 0
#> 18 per group 0.1 0.4 0.3 0.27614 0.209190 0.51467 0
#> 18 per group 0.2 0.5 0.3 0.51809 0.078087 0.40382 0
#> 18 per group 0.3 0.6 0.3 0.75066 0.020935 0.22841 0
#> 18 per group 0.4 0.7 0.3 0.90834 0.003556 0.08811 0
#> 24 per group 0.0 0.3 0.3 0.07551 0.456998 0.46750 0
#> 24 per group 0.1 0.4 0.3 0.26111 0.192246 0.54664 0
#> 24 per group 0.2 0.5 0.3 0.53935 0.056720 0.40393 0
#> 24 per group 0.3 0.6 0.3 0.79565 0.010812 0.19353 0
#> 24 per group 0.4 0.7 0.3 0.94297 0.001128 0.05590 0
plot(cmp)With an effect of 0.3, the probability of a Go decision is 0.80 with 24 subjects per group, against 0.69 with 12 subjects per group. Other parts of a design are compared in the same way, for example the borrowing of external control data through a power prior:
ext <- des |>
qdm_external(external_c = borrow(data_binary(n = 40, y = 12), a0 = 0.5))
qdm_compare(list(Concurrent = des, Borrowing = ext), scen) |>
plot(decisions = c("Go", "NoGo"))qdm_find_n() is the counterpart of
qdm_calibrate(): with the thresholds fixed, it finds the
smallest candidate sample size for which the probability of meeting the
Go criterion when the treatment has no effect, and that of meeting the
NoGo criterion when the effect is 0.3, are both at most 0.1:
res <- qdm_find_n(des,
scenario_go = data.frame(pi_t = 0.3, pi_c = 0.3),
scenario_nogo = data.frame(pi_t = 0.6, pi_c = 0.3),
target_go = 0.1, target_nogo = 0.1,
n_t = seq(6, 30, by = 2))
res
#> Search for the sample size (exact enumeration of the outcomes)
#> Targets: P(Go criterion met | scenario_go) <= 0.1 and P(NoGo criterion met | scenario_nogo) <= 0.1
#> Smallest candidate that meets the targets: n_t = 16, n_c = 16
#> P(Go criterion met | scenario_go) = 0.08755
#> P(NoGo criterion met | scenario_nogo) = 0.02621
#> Smallest candidate from which all larger candidates meet the targets: n_t = 20, n_c = 20
#> Probabilities for the candidate sample sizes
#> n_t n_c prob_go prob_nogo met
#> 6 6 0.17048 0.083872 FALSE
#> 8 8 0.20540 0.065947 FALSE
#> 10 10 0.10986 0.052145 FALSE
#> 12 12 0.13165 0.041368 FALSE
#> 14 14 0.13978 0.032875 FALSE
#> 16 16 0.08755 0.026211 TRUE
#> 18 18 0.10072 0.020935 FALSE
#> 20 20 0.05948 0.016762 TRUE
#> 22 22 0.06868 0.013449 TRUE
#> 24 24 0.07551 0.010812 TRUE
#> 26 26 0.04742 0.008708 TRUE
#> 28 28 0.05382 0.007121 TRUE
#> 30 30 0.03304 0.005780 TRUE
#> Decision probabilities with the chosen sample size
#> scenario pi_t pi_c Go NoGo Gray Miss
#> scenario_go 0.3 0.3 0.08755 0.42931 0.4831 0
#> scenario_nogo 0.6 0.3 0.69066 0.02621 0.2831 0
plot(res)The smallest candidate that meets both targets has 16 subjects per
group. The outcomes of a binary endpoint are discrete, so the
probabilities do not decrease steadily as the sample size increases:
here the larger candidate with 18 subjects per group does not meet them,
and every candidate from 20 subjects per group on does.
res$design is the design with the chosen sample size.
as.data.frame() converts a decision, a calibration or a
search for the sample size to a data frame with one row, so that results
can be combined with rbind() and written to a file with
write.csv(). For example, the decisions for the same data
with three prior distributions:
priors <- list(Jeffreys = prior_beta(0.5, 0.5), Uniform = prior_beta(1, 1),
Skeptical = prior_beta(2, 6))
decisions <- lapply(priors, function(p) {
des |>
qdm_prior(prior_t = p, prior_c = p) |>
qdm_decide(data_t = data_binary(12, 8), data_c = data_binary(12, 4))
})
do.call(rbind, lapply(decisions, as.data.frame))
#> decision prob_go gamma_go met_go prob_nogo gamma_nogo met_nogo
#> Jeffreys Go 0.7296953 0.5 TRUE 0.1293936 0.8 FALSE
#> Uniform Go 0.6937871 0.5 TRUE 0.1482919 0.8 FALSE
#> Skeptical Go 0.5075200 0.5 TRUE 0.2487769 0.8 FALSEThe operating characteristics of qdm_oc() and
qdm_compare() are data frames already.
plot() of a decision shows how the data lead to it. For
one endpoint and a criterion based on posterior probability, it shows
the posterior density of the treatment effect with the Go and NoGo
regions:
For a predictive criterion, it shows the predictive probabilities with their thresholds, and for two endpoints the probabilities of the regions.
show_code() writes the R code that creates a design, as
a pipe of the design steps or as a call of the design_*()
function:
show_code(res$design)
#> design <- qdm_endpoint("binary") |>
#> qdm_sample_size(n_t = 16, n_c = 16) |>
#> qdm_prior(prior_t = prior_beta(a = 0.5, b = 0.5),
#> prior_c = prior_beta(a = 0.5, b = 0.5)) |>
#> qdm_criterion(criterion_posterior(theta_tv = 0.2, theta_mav = 0.1,
#> gamma_go = 0.5, gamma_nogo = 0.8)) |>
#> qdm_build()
show_code(res$design, style = "design")
#> design <- design_binary(
#> n_t = 16, n_c = 16, prior_t = prior_beta(a = 0.5, b = 0.5),
#> prior_c = prior_beta(a = 0.5, b = 0.5),
#> criterion = criterion_posterior(theta_tv = 0.2, theta_mav = 0.1,
#> gamma_go = 0.5, gamma_nogo = 0.8)
#> )show_report(x, code = TRUE) adds the code to the end of
the report of a design or of a result (see
vignette("pipe")).