@@ -155,3 +155,61 @@ singlearm_beta_type1_exact <- function(n_t, M, threshold, prior = "flat", a_base
155155 .Call(`_bcts_singlearm_beta_type1_exact` , n_t , M , threshold , prior , a_base , b_base , p_null )
156156}
157157
158+ # ' Estimate Power for Bayesian RCT Using Beta-Binomial Conjugate Model (C++)
159+ # '
160+ # ' Performs Monte Carlo simulation to estimate the statistical power of a
161+ # ' Bayesian randomized controlled trial (RCT) using conjugate Beta-Binomial
162+ # ' models for the control and treatment arms. The function supports flat priors
163+ # ' and power priors on the control arm, and allows for fully customizable
164+ # ' baseline Beta prior parameters for both arms.
165+ # '
166+ # ' A trial is declared successful if the posterior probability
167+ # ' \eqn{Pr(\theta_t - \theta_c > M \mid \text{data}) \ge \gamma}.
168+ # '
169+ # ' @param B Integer. Number of simulated trials.
170+ # ' @param p_c,p_t Numeric in \[0, 1\]. True response probabilities in the control and treatment arms.
171+ # ' @param n_c,n_t Integers. Sample sizes in the control and treatment arms.
172+ # ' @param M Numeric. Margin on the risk-difference scale:
173+ # ' - Negative for non-inferiority,
174+ # ' - Zero for equivalence,
175+ # ' - Positive for superiority.
176+ # ' @param threshold Numeric in (0, 1). Posterior probability threshold \eqn{\gamma}.
177+ # ' @param prior Character. Type of prior to use:
178+ # ' - `"flat"`: independent Beta priors for both arms,
179+ # ' - `"power"`: power prior on the control arm, flat prior on treatment.
180+ # ' @param prior_args List of prior hyperparameters. The following elements are supported:
181+ # ' - `a0`: Discount factor for historical control data (only used if `prior = "power"`).
182+ # ' - `y_0`, `n_0`: Number of responses and total patients in the historical control data.
183+ # ' - `a_base_c`, `b_base_c`: Shape parameters of the Beta prior for the control arm.
184+ # ' - `a_base_t`, `b_base_t`: Shape parameters of the Beta prior for the treatment arm.
185+ # ' - Defaults for all `a_base_*` and `b_base_*` values are 1 (i.e., flat prior).
186+ # ' @param n_draws Integer. Number of posterior draws per trial for estimating the probability.
187+ # ' @param show_progress Logical. Show progress bar in the console.
188+ # '
189+ # ' @return A logical vector of length `B`, indicating for each trial whether the decision
190+ # ' criterion was met (i.e., trial declared successful).
191+ # '
192+ # ' @details This function uses Rcpp and vectorized binomial simulation to increase speed.
193+ # ' Posterior samples are drawn from Beta distributions parameterized using either flat priors
194+ # ' or power priors (for control) combined with observed trial data.
195+ # '
196+ # ' @examples
197+ # ' prior_args <- list(
198+ # ' a0 = 0.5, y_0 = 20, n_0 = 30,
199+ # ' a_base_c = 1, b_base_c = 1,
200+ # ' a_base_t = 2, b_base_t = 2
201+ # ' )
202+ # ' decisions <- rct_power_beta_binom_cpp_vec(
203+ # ' B = 1000, p_c = 0.8, p_t = 0.8,
204+ # ' n_c = 25, n_t = 25,
205+ # ' M = -0.1, threshold = 0.9,
206+ # ' prior = "power", prior_args = prior_args,
207+ # ' n_draws = 2000, show_progress = FALSE
208+ # ' )
209+ # ' mean(decisions) # Estimated power
210+ # '
211+ # ' @export
212+ rct_power_beta_binom_cpp_vec <- function (B , p_c , p_t , n_c , n_t , M , threshold , prior , prior_args , n_draws , show_progress = TRUE ) {
213+ .Call(`_bcts_rct_power_beta_binom_cpp_vec` , B , p_c , p_t , n_c , n_t , M , threshold , prior , prior_args , n_draws , show_progress )
214+ }
215+
0 commit comments