|
| 1 | +# Generated by using Rcpp::compileAttributes() -> do not edit by hand |
| 2 | +# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 |
| 3 | + |
| 4 | +beta_prob_gt <- function(a, b, M, n_draws) { |
| 5 | + .Call(`_bcts_beta_prob_gt`, a, b, M, n_draws) |
| 6 | +} |
| 7 | + |
| 8 | +#' @title Compute p-values for a t-distribution with Fixed Degrees of Freedom |
| 9 | +#' |
| 10 | +#' @description Simulates a single-arm binomial trial with a conjugate Beta prior, |
| 11 | +#' and computes the Bayesian power - the proportion of trials where the posterior |
| 12 | +#' probability that the response rate exceeds a threshold \code{M} is greater than or equal |
| 13 | +#' to a specified decision threshold. |
| 14 | +#' |
| 15 | +#' @param B Integer. Number of trial simulations. |
| 16 | +#' @param p_t Numeric in \[0, 1\]. True response probability for the treatment arm. |
| 17 | +#' @param n_t Integer. Sample size of the treatment arm. |
| 18 | +#' @param M Numeric in \[0, 1\]. Decision threshold on the response rate, e.g., \code{M = 0.6}. |
| 19 | +#' @param threshold Numeric in \[0, 1\]. Posterior probability cutoff for declaring success, |
| 20 | +#' e.g., \code{0.95}. |
| 21 | +#' @param prior Character string. Either \code{"flat"} for a Beta(1,1) prior or |
| 22 | +#' \code{"beta"} to specify a custom prior using \code{a_base} and \code{b_base}. |
| 23 | +#' @param a_base Numeric. Alpha parameter for the Beta prior (only used if \code{prior = "beta"}). |
| 24 | +#' @param b_base Numeric. Beta parameter for the Beta prior (only used if \code{prior = "beta"}). |
| 25 | +#' @param n_draws Integer. Number of posterior draws per trial. |
| 26 | +#' @param show_progress Logical. If \code{TRUE}, prints a simple progress bar to console. |
| 27 | +#' |
| 28 | +#' @return A list with: estimate (power), mc_se, successes, B. |
| 29 | +#' |
| 30 | +#' @examples |
| 31 | +#' singlearm_beta_power( |
| 32 | +#' B = 1000, p_t = 0.75, n_t = 35, M = 0.60, |
| 33 | +#' threshold = 0.95, prior = "flat", n_draws = 2000 |
| 34 | +#' ) |
| 35 | +#' |
| 36 | +#' @author Thomas Debray \email{[email protected]} |
| 37 | +#' @export |
| 38 | +singlearm_beta_power <- function(B, p_t, n_t, M, threshold, prior = "flat", a_base = 1, b_base = 1, n_draws = 2000L, show_progress = TRUE) { |
| 39 | + .Call(`_bcts_singlearm_beta_power`, B, p_t, n_t, M, threshold, prior, a_base, b_base, n_draws, show_progress) |
| 40 | +} |
| 41 | + |
| 42 | +#' @title Estimate Type-I Error for Single-Arm Trial |
| 43 | +#' |
| 44 | +#' @description Simulates a single-arm binomial trial under the null hypothesis, |
| 45 | +#' and computes the type-I error: the proportion of simulations where posterior |
| 46 | +#' Pr(θ > M) ≥ threshold even though θ = p_null. |
| 47 | +#' |
| 48 | +#' @param B Integer. Number of simulations. |
| 49 | +#' @param n_t Integer. Sample size of the treatment arm. |
| 50 | +#' @param M Numeric. Decision threshold for θ (on probability scale, e.g., 0.6). |
| 51 | +#' @param threshold Posterior probability threshold γ (e.g., 0.95). |
| 52 | +#' @param prior "flat" or "beta". |
| 53 | +#' @param a_base Alpha parameter for Beta prior (if prior = "beta"). |
| 54 | +#' @param b_base Beta parameter for Beta prior (if prior = "beta"). |
| 55 | +#' @param n_draws Number of posterior draws per trial. |
| 56 | +#' @param show_progress Logical. Show progress in console? |
| 57 | +#' |
| 58 | +#' @return A list with \code{estimate} (type-I error), \code{mc_se}, \code{B}, and \code{rejections}. |
| 59 | +#' |
| 60 | +#' @examples |
| 61 | +#' singlearm_beta_type1( |
| 62 | +#' B = 1000, n_t = 35, M = 0.6, |
| 63 | +#' threshold = 0.95, prior = "flat", n_draws = 2000 |
| 64 | +#' ) |
| 65 | +#' |
| 66 | +#' @author Thomas Debray \email{[email protected]} |
| 67 | +#' @export |
| 68 | +singlearm_beta_type1 <- function(B, n_t, M, threshold, prior = "flat", a_base = 1, b_base = 1, n_draws = 2000L, show_progress = TRUE) { |
| 69 | + .Call(`_bcts_singlearm_beta_type1`, B, n_t, M, threshold, prior, a_base, b_base, n_draws, show_progress) |
| 70 | +} |
| 71 | + |
0 commit comments