Writes a report of a design, or of the result of an analysis of a design,
as a draft of the corresponding sections of a study protocol: the study
design, the statistical model and the prior distributions, the decision
criteria with their formulas, the computation of the probabilities and the
result. The report is meant to be copied into a protocol and edited there.
It can end a pipe of the design steps (see qdm_endpoint) and
of the functions that use a design.
Usage
show_report(
x,
file_type = c("html", "text"),
file = NULL,
title = NULL,
digits = 3L,
open = interactive(),
code = FALSE
)Arguments
- x
A design (created by a
design_*()function such asdesign_binary), a design specification (started byqdm_endpoint), or a result ofqdm_oc,qdm_calibrate,qdm_find_n,qdm_boundaryorqdm_decide.- file_type
"html"(the default) for an HTML file or"text"for a plain text file.- file
Name of the file to write, or
NULL(the default) for a temporary file with the extension.htmlor.txt.- title
Title of the report, or
NULLfor a title that depends onx.- digits
Number of decimal places of the probabilities (a whole number from 1 to 10). The parameters are shown with up to four significant digits.
- open
Whether to show the report: an HTML report is opened in the viewer of RStudio, if the file is in the temporary folder of the R session, or else in the web browser, and a text report is printed in the console. By default the report is shown when R is used interactively.
- code
TRUEto end the report with the R code that creates the design (seeshow_code). By default, the code is left out.
Details
The content of the report depends on x:
- A design or a design specification
The design.
- A result of
qdm_oc The design and the table of the operating characteristics.
- A result of
qdm_calibrate The design with the calibrated thresholds, how the thresholds were chosen, and the decision probabilities under the two scenarios of the calibration.
- A result of
qdm_find_n The design with the chosen sample sizes, how they were chosen, the probabilities for the candidates and the decision probabilities under the two scenarios.
- A result of
qdm_boundary The design and the decision boundaries.
- A result of
qdm_decide The design, the observed data, the probabilities of the criteria, the decision and the posterior distributions.
The formulas are written in LaTeX between dollar signs. In the HTML report they are displayed by MathJax, which the web browser loads from a content delivery network, so an internet connection is needed to display them (without one, the LaTeX code is shown). The text report is plain text in Markdown format, with the formulas in LaTeX. A PDF file can be made by printing the HTML report from the web browser.
Examples
spec <- qdm_endpoint("binary") |>
qdm_sample_size(n_t = 12, n_c = 12) |>
qdm_prior(prior_t = prior_beta(0.5, 0.5),
prior_c = prior_beta(0.5, 0.5)) |>
qdm_criterion(criterion_posterior(theta_tv = 0.2, theta_mav = 0.1,
gamma_go = 0.5, gamma_nogo = 0.8))
# Text report of the operating characteristics with the R code of the
# design, printed in the console
spec |>
qdm_oc(data.frame(pi_t = c(0.3, 0.5), pi_c = 0.3)) |>
show_report(file_type = "text", open = TRUE, code = TRUE)
#> # Decision criteria and operating characteristics
#>
#> ## Study design
#>
#> The proof-of-concept study has one binary endpoint and will enroll 12 subjects in the treatment group and 12 subjects in the control group.
#>
#> ## Statistical model
#>
#> The number of responders among the $n_k$ subjects of group $k$ ($k = t, c$ for the treatment and control groups) follows a binomial distribution with response rate $\pi_k$, and the treatment effect is the difference in response rates, $\theta = \pi_t - \pi_c$.
#>
#> The prior distribution of the treatment group is $\pi_t \sim \textrm{Beta}(0.5, 0.5)$. The prior distribution of the control group is $\pi_c \sim \textrm{Beta}(0.5, 0.5)$. The posterior distributions have closed forms.
#>
#> ## Decision criteria
#>
#> The decision will be based on the posterior probability of the treatment effect $\theta$ given the data $D$ of the study, with the target value $\theta_{TV} = 0.2$ and the minimum acceptable value $\theta_{MAV} = 0.1$.
#>
#> - Go criterion: $\Pr(\theta > 0.2 \mid D) \ge 0.5$
#> - NoGo criterion: $\Pr(\theta \le 0.1 \mid D) \ge 0.8$
#>
#> The decision will be Go if only the Go criterion is met, NoGo if only the NoGo criterion is met, and Gray if neither is met; if both are met, the decision is called Miss. Because $\gamma_{go} + \gamma_{nogo} > 1$, the two criteria cannot both be met.
#>
#> ## Computation of the probabilities
#>
#> The probabilities of the decision criteria are computed by numerical integration.
#>
#> ## Operating characteristics
#>
#> The probabilities of Go, NoGo, Gray and Miss decisions under scenarios for the true parameters (exact enumeration of the outcomes) are as follows.
#>
#> | $\pi_t$ | $\pi_c$ | Go | NoGo | Gray | Miss |
#> |---|---|---|---|---|---|
#> | 0.3 | 0.3 | 0.132 | 0.417 | 0.451 | 0.000 |
#> | 0.5 | 0.3 | 0.488 | 0.109 | 0.402 | 0.000 |
#>
#> $\pi_t$ and $\pi_c$ are the true response rates of the treatment and control groups.
#>
#> ## R code
#>
#> The following R code creates the design with BayesianQDM.
#>
#> design <- qdm_endpoint("binary") |>
#> qdm_sample_size(n_t = 12, n_c = 12) |>
#> 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()
#>
#> Report written by BayesianQDM 1.1.0.
# HTML report of a decision in a temporary file, which is opened when R
# is used interactively
path <- spec |>
qdm_decide(data_t = data_binary(12, 9), data_c = data_binary(12, 4)) |>
show_report()
