Package {bayesDP}


Type: Package
Title: Implementation of the Bayesian Discount Prior Approach for Clinical Trials
Version: 1.3.9
Depends: R (≥ 3.6.0), ggplot2, methods, survival
Description: Functions for data augmentation using the Bayesian discount prior method for single arm and two-arm clinical trials, as described in Haddad et al. (2017) <doi:10.1080/10543406.2017.1300907>. The discount power prior methodology was developed in collaboration with the Medical Device Innovation Consortium (MDIC) Computer Modeling & Simulation Working Group.
LazyLoad: yes
License: GPL-3 | file LICENSE
URL: https://github.com/graemeleehickey/bayesDP, https://graemeleehickey.github.io/bayesDP/, https://CRAN.R-project.org/package=bayesDP
BugReports: https://github.com/graemeleehickey/bayesDP/issues
NeedsCompilation: yes
Imports: detectseparation, generics, MCMCpack, Rcpp, tibble
LinkingTo: Rcpp, RcppArmadillo
RoxygenNote: 7.3.3
Encoding: UTF-8
Suggests: broom, covr, knitr, modelsummary, posterior, rmarkdown, testthat, withr
VignetteBuilder: knitr
Packaged: 2026-11-24 19:33:22 UTC; runner
Author: Shawn Balcome [aut], Donnie Musgrove [aut], Tarek Haddad [aut], Graeme L. Hickey ORCID iD [cre, aut], Christopher Jackson [ctb] (For the ppexp R code that was ported to C++.)
Maintainer: Graeme L. Hickey <graemeleehickey@gmail.com>
Repository: CRAN
Date/Publication: 2026-11-24 20:20:02 UTC

Bayesian Discount Prior: Historical Data Weight (alpha)

Description

alpha_discount can be used to estimate the weight applied to historical data in the context of a one- or two-arm clinical trial. It is also used by the survival fitting function and discount plots.

Usage

alpha_discount(
  p_hat = NULL,
  discount_function = "weibull",
  alpha_max = 1,
  weibull_scale = 0.135,
  weibull_shape = 3
)

Arguments

p_hat

numeric scalar or vector. Current-historical comparisons in [0, 1]. This value can be the output of probability_discount or a value between 0 and 1.

discount_function

character. Specify the discount function to use. Currently supports weibull, scaledweibull, and identity. The discount function scaledweibull scales the output of the Weibull CDF to have a max value of 1. The identity discount function uses the supplied comparison directly as the discount weight. Default value is "weibull".

alpha_max

scalar. Maximum weight the discount function can apply. Default is 1.

weibull_scale

scalar. Scale parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 0.135.

weibull_shape

scalar. Shape parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 3.

Details

Given inputs p_hat, discount_function, alpha_max, weibull_shape, and weibull_scale the output is the weight that would be applied to historical data in the context of a one- or two-arm clinical trial.

Value

A numeric historical weight (or vector of weights when p_hat is a vector), scaled by alpha_max.

References

Haddad, T., Himes, A., Thompson, L., Irony, T., Nair, R. MDIC Computer Modeling and Simulation working group.(2017) Incorporation of stochastic engineering models as prior information in Bayesian medical device trials. Journal of Biopharmaceutical Statistics, 1-15.

Examples

alpha_discount(0.5)

alpha_discount(0.5, discount_function = "identity")

Bayesian Discount Prior: Binomial counts

Description

bdpbinomial is used for estimating posterior samples from a binomial outcome where an informative prior is used. The prior weight is determined using a discount function. This code is modeled after the methodologies developed in Haddad et al. (2017).

Usage

bdpbinomial(
  y_t = NULL,
  N_t = NULL,
  y0_t = NULL,
  N0_t = NULL,
  y_c = NULL,
  N_c = NULL,
  y0_c = NULL,
  N0_c = NULL,
  discount_function = "identity",
  alpha_max = 1,
  fix_alpha = FALSE,
  a0 = 1,
  b0 = 1,
  number_mcmc = 10000,
  weibull_scale = 0.135,
  weibull_shape = 3,
  method = "mc",
  compare = TRUE
)

Arguments

y_t

scalar. Number of events for the current treatment group.

N_t

scalar. Sample size of the current treatment group.

y0_t

scalar. Number of events for the historical treatment group.

N0_t

scalar. Sample size of the historical treatment group.

y_c

scalar. Number of events for the current control group.

N_c

scalar. Sample size of the current control group.

y0_c

scalar. Number of events for the historical control group.

N0_c

scalar. Sample size of the historical control group.

discount_function

character. Specify the discount function to use. Currently supports weibull, scaledweibull, and identity. The discount function scaledweibull scales the output of the Weibull CDF to have a max value of 1. The identity discount function uses the transformed comparison directly as the discount weight. Default value is "identity".

alpha_max

scalar in [0, 1]. Maximum weight the discount function can apply. Default is 1. For a two-arm trial, users may specify a vector of two values where the first value is used to weight the historical treatment group and the second value is used to weight the historical control group.

fix_alpha

logical. Fix alpha at alpha_max? Default value is FALSE.

a0

positive, finite scalar. Prior value for a beta shape parameter. Default is 1.

b0

positive, finite scalar. Prior value for a beta shape parameter. Default is 1.

number_mcmc

integer of at least 2. Number of Monte Carlo simulations. Default is 10000.

weibull_scale

scalar. Scale parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 0.135. For a two-arm trial, users may specify a vector of two values where the first value is used to estimate the weight of the historical treatment group and the second value is used to estimate the weight of the historical control group. Not used when discount_function = "identity".

weibull_shape

scalar. Shape parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 3. For a two-arm trial, users may specify a vector of two values where the first value is used to estimate the weight of the historical treatment group and the second value is used to estimate the weight of the historical control group. Not used when discount_function = "identity".

method

character. Analysis method with respect to estimation of the weight parameter alpha. Default method "mc" estimates alpha for each Monte Carlo iteration, giving a distribution of generated weights. Increasing the number of draws improves numerical precision but does not remove the spread of that distribution. These weights are not draws from a separately specified prior/posterior model for alpha. Alternate value "fixed" estimates alpha once and holds it fixed throughout the analysis. See the bdpbinomial vignette
vignette("bdpbinomial-vignette", package = "bayesDP") for more details.

compare

logical. Should a comparison object be included in the fit? For a one-arm analysis, the comparison object is simply the posterior draws of the treatment group parameter. For a two-arm analysis, the comparison object is the posterior draws of the treatment effect that compares treatment and control. If compare = TRUE, the comparison object is accessible in the final slot, else the final slot is NULL. Default is TRUE.

Details

Historical borrowing is assessed separately within each arm by comparing event probabilities. With method = "fixed", estimate the probability q that the current event probability is below the historical one. The discount input is p = 2 * min(q, 1 - q) and the weight is alpha_max * W(p) for the selected discount function W. This comparison is not a posterior probability of equality or equivalence. Choosing fix_alpha = TRUE prespecifies the weight instead.

Each supplied group requires scalar, finite integer event counts and sample sizes, with N \geq 1 and 0 \leq y \leq N. Both zero-event and all-event groups are allowed. Omit an optional group by leaving both inputs NULL; zero sample size does not denote an absent group. Inputs and borrowing settings are checked before sampling, including when weights are prescribed. Weibull parameters must be positive and finite when used to estimate a weight.

In the second stage, posterior estimation is performed where the discount function parameter, alpha, is incorporated in all posterior estimation procedures.

To carry out a single arm (OPC) analysis, data for the current treatment (y_t and N_t) and historical treatment (y0_t and N0_t) must be input. The results are then based on the posterior distribution of the current data augmented by the historical data.

To carry our a two-arm (RCT) analysis, data for the current treatment and at least one of current or historical control data must be input. The results are then based on the posterior distribution of the difference between current treatment and control, augmented by available historical data.

For more details, see the bdpbinomial vignette:
vignette("bdpbinomial-vignette", package = "bayesDP")

Value

bdpbinomial returns an object of class "bdpbinomial". The functions summary and print are used to obtain and print a summary of the results, including user inputs. The plot function displays visual outputs as well.

An object of class bdpbinomial is a list containing at least the following components:

posterior_treatment

list. Entries contain values related to the treatment group:

  • alpha_discount numeric. Alpha value, the weighting parameter of the historical data.

  • p_hat numeric. The current-historical comparison between the current and historical data.

  • posterior vector. A vector of length number_mcmc containing posterior Monte Carlo samples of the event rate of the treatment group. If historical treatment data is present, the posterior incorporates the weighted historical data.

  • posterior_flat vector. A vector of length number_mcmc containing Monte Carlo samples of the event rate of the current treatment group under a flat/non-informative prior, i.e., no incorporation of the historical data.

  • prior vector. If historical treatment data is present, a vector of length number_mcmc containing Monte Carlo samples of the event rate of the historical treatment group under a flat/non-informative prior.

posterior_control

list. Similar entries as posterior_treament. Only present if a control group is specified.

final

list. Contains the final comparison object, dependent on the analysis type:

  • One-arm analysis: vector. Posterior chain of binomial proportion.

  • Two-arm analysis: vector. Posterior chain of binomial proportion difference comparing treatment and control groups.

args1

list. Entries contain user inputs. In addition, the following elements are output:

  • arm2 binary indicator. Used internally to indicate one-arm or two-arm analysis.

  • intent character. Denotes current/historical status of treatment and control groups.

References

Haddad, T., Himes, A., Thompson, L., Irony, T., Nair, R. MDIC Computer Modeling and Simulation working group.(2017) Incorporation of stochastic engineering models as prior information in Bayesian medical device trials. Journal of Biopharmaceutical Statistics, 1-15.

See Also

summary, print, and plot for details of each of the supported methods.

Examples

# One-arm trial (OPC) example
fit <- bdpbinomial(
  y_t = 10,
  N_t = 500,
  y0_t = 25,
  N0_t = 250,
  method = "fixed"
)
summary(fit)
print(fit)
## Not run: 
plot(fit)

## End(Not run)

# Two-arm (RCT) example
fit2 <- bdpbinomial(
  y_t = 10,
  N_t = 500,
  y0_t = 25,
  N0_t = 250,
  y_c = 8,
  N_c = 500,
  y0_c = 20,
  N0_c = 250,
  method = "fixed"
)
summary(fit2)
print(fit2)
## Not run: 
plot(fit2)

## End(Not run)


Bayesian Discount Prior: Two-Arm Linear Regression

Description

bdplm is used to estimate the treatment effect in the presence of covariates using the regression analysis implementation of the Bayesian discount prior. summary and print methods are supported. Currently, the function only supports a two-arm clinical trial where all of current treatment, current control, historical treatment, and historical control data are present

Usage

bdplm(
  formula = formula,
  data = data,
  data0 = NULL,
  prior_treatment_effect = NULL,
  prior_control_effect = NULL,
  prior_treatment_sd = NULL,
  prior_control_sd = NULL,
  prior_covariate_effect = 0,
  prior_covariate_sd = 10000,
  number_mcmc_alpha = 5000,
  number_mcmc_sigmagrid = 5000,
  number_mcmc_sigma = 100,
  number_mcmc_beta = 10000,
  discount_function = "identity",
  alpha_max = 1,
  fix_alpha = FALSE,
  weibull_scale = 0.135,
  weibull_shape = 3,
  method = "mc",
  centering = "pooled"
)

Arguments

formula

an object of class "formula." See "Details" for more information, including specification of treatment data indicators.

data

a data frame containing the current data variables in the model. A column named treatment must be present; treatment must be binary and indicate treatment group vs. control group.

data0

a data frame containing the historical data variables in the model. The column labels of data and data0 must match.

prior_treatment_effect

scalar. The historical adjusted treatment effect. If left NULL, value is estimated from the historical data.

prior_control_effect

scalar. The historical adjusted control effect. If left NULL, value is estimated from the historical data.

prior_treatment_sd

scalar. The standard deviation of the historical adjusted treatment effect. If left NULL, value is estimated from the historical data.

prior_control_sd

scalar. The standard deviation of the historical adjusted control effect. If left NULL, value is estimated from the historical data.

prior_covariate_effect

vector. The prior mean(s) of the covariate effect(s). Default value is zero. If a single value is input, the the scalar is repeated to the length of the input covariates. Otherwise, care must be taken to ensure the length of the input matches the number of covariates.

prior_covariate_sd

vector. The prior standard deviation(s) of the covariate effect(s). Default value is 1e4. If a single value is input, the the scalar is repeated to the length of the input covariates. Otherwise, care must be taken to ensure the length of the input matches the number of covariates. Under method = "fixed", the effective prior SD is the supplied SD multiplied by 1e6 because covariate prior precision is multiplied by 1e-12. Under method = "mc", covariate prior precision is zero, so neither the supplied mean nor SD influences the fit. These arguments do not specify ordinary informative covariate priors.

number_mcmc_alpha

scalar. Number of Monte Carlo simulations for estimating the historical data weight. Default is 5000.

number_mcmc_sigmagrid

scalar. Grid size for computing sigma. Default is 5000. See "Details" for more information.

number_mcmc_sigma

scalar. Number of Monte Carlo simulations for estimating sigma. Default is 1000. See "Details" for more information.

number_mcmc_beta

scalar. Number of Monte Carlo simulations for estimating beta, the vector of regression coefficients. Default is 10000.

discount_function

character. Specify the discount function to use. Currently supports weibull, scaledweibull, and identity. The discount function scaledweibull scales the output of the Weibull CDF to have a max value of 1. The identity discount function uses the posterior probability directly as the discount weight. Default value is "identity".

alpha_max

scalar. Maximum weight the discount function can apply. Default is 1. Users may specify a vector of two values where the first value is used to weight the historical treatment group and the second value is used to weight the historical control group.

fix_alpha

logical. Fix alpha at alpha_max? Default value is FALSE.

weibull_scale

scalar. Scale parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 0.135. Users may specify a vector of two values where the first value is used to estimate the weight of the historical treatment group and the second value is used to estimate the weight of the historical control group. Not used when discount_function = "identity".

weibull_shape

scalar. Shape parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 3. Users may specify a vector of two values where the first value is used to estimate the weight of the historical treatment group and the second value is used to estimate the weight of the historical control group. Not used when discount_function = "identity".

method

character. Analysis method with respect to estimation of the weight paramter alpha. Default method "mc" estimates alpha for each Monte Carlo iteration, giving a distribution of generated weights rather than numerical error around a fixed weight. Alternate value "fixed" estimates alpha once and holds it fixed throughout the analysis. See the the bdplm vignette
vignette("bdplm-vignette", package = "bayesDP") for more details.

centering

character. How to center covariates: "pooled" (default) uses current and historical observations, "current" uses current observations only, and "historical" uses historical observations only. "none" leaves covariates unchanged. Each centering mean includes both treatment arms and gives equal weight to each included observation, without discounting. The same means are subtracted from both datasets, including encoded factor covariates. The response and treatment indicator are not centered.

Details

bdplm uses a two-stage approach for determining the strength of historical data in estimation of an adjusted mean or covariate effect. In the first stage, a discount function is used that that defines the maximum strength of the historical data and discounts based on disagreement with the current data. Disagreement between current and historical data is determined by stochastically comparing the respective posterior distributions under noninformative priors. Here with a two-arm regression analysis, the comparison is the proability (p) that the covariate effect of an historical data indicator is significantly different from zero. The comparison metric p is then input into the discount function and the final strength of the historical data is returned (alpha).

In the second stage, posterior estimation is performed where the discount function parameter, alpha, is used to weight the historical data effects.

The formula must include an intercept (i.e., do not use -1 in the formula) and both data and data0 must be present. The column names of data and data0 must match. See examples below for example usage.

Formula offsets are not supported. Calls to offset() or stats::offset() cause an error before fitting, including offsets that are zero or cancel each other. This restriction applies with either method, prescribed weights, no borrowing, or supplied historical priors.

Internally, the model is parameterized without a fixed intercept, using separate treatment and control means rather than an intercept plus a treatment effect. In this parameterization the arm means are the fitted values at covariate = 0, so when covariates are not centered the treatment- and control-mean estimators can become strongly correlated and their standard errors can reflect extrapolation to covariate = 0. This can affect the discount-prior construction and historical borrowing. To guard against this, bdplm defaults to centering each covariate at its pooled current and historical mean. The centering argument selects the data used to calculate the mean or disables centering with "none". The reported intercept is transformed back to the original covariate scale. Specifically, if \bar{x}_j is the selected mean of covariate j (or zero under centering = "none") and \beta_j its estimated effect, the reported intercept is \beta_0 = \beta_0^{c} - \sum_j \beta_j \bar{x}_j, where \beta_0^{c} is the control-arm mean at the selected covariate reference values. This back-transformation leaves the treatment effect and slopes unchanged; the reported intercept remains the control-arm mean at covariate = 0 on the original scale. With mean centering enabled, the treatment effect and covariate slopes are invariant to a location shift of a covariate; the reported intercept changes with the covariate origin. Centering does not generally make the arm-mean estimators independent, and their covariance is not retained in the diagonal historical prior.

Changing centering can change the estimated treatment effect and its posterior uncertainty, because the independent historical arm priors are constructed at the selected covariate reference values. Transforming the intercept back to the original covariate scale does not remove this dependence. With centering = "none", the historical arm priors refer to covariate = 0, which can involve extrapolation, and results can depend on the covariate origin. User-supplied historical arm-prior means and SDs must describe the adjusted arm means at the selected covariate reference values.

The marginal posterior of the residual variance is evaluated numerically. Candidate variance values are equally spaced under "fixed" and uniformly sampled under "mc". Their bounds use extreme quantiles of an inverse-gamma approximation from a weighted regression on the augmented data. The number_mcmc_sigma variance draws are sampled with replacement using marginal density weights, followed by conditional coefficient draws. Under "mc", each candidate variance is paired with a generated historical-weight vector. Increase the grid and draw counts to assess numerical stability; the Monte Carlo method requires number_mcmc_sigmagrid <= number_mcmc_alpha.

Value

bdplm returns an object of class "bdplm".

An object of class "bdplm" is a list containing at least the following components:

posterior

data frame. The posterior draws of the intercept, treatment effect, covariate effects, and residual standard deviation sigma.

alpha_discount

data frame. Historical weights for treatment and control, with one row under "fixed" or one row per comparison draw under "mc". These are weights, not probabilities of equality.

estimates

list. The coefficients component contains posterior means, and se contains posterior standard deviations, for the intercept, treatment effect, covariate effects, and residual SD.

args1

list. The original call, the analysis data after any centering, the centering choice, and the named covariate_means used to restore the original covariate scale when calculating residual summaries. Under centering = "none", covariate_means contains zeros because no values are subtracted.

Examples

# Set sample sizes
n_t <- 30 # Current treatment sample size
n_c <- 30 # Current control sample size
n_t0 <- 80 # Historical treatment sample size
n_c0 <- 80 # Historical control sample size

# Treatment group vectors for current and historical data
treatment <- c(rep(1, n_t), rep(0, n_c))
treatment0 <- c(rep(1, n_t0), rep(0, n_c0))

# Simulate a covariate effect for current and historical data
x <- rnorm(n_t + n_c, 1, 5)
x0 <- rnorm(n_t0 + n_c0, 1, 5)

# Simulate outcome:
# - Intercept of 10 for current and historical data
# - Treatment effect of 31 for current data
# - Treatment effect of 30 for historical data
# - Covariate effect of 3 for current and historical data
Y <- 10 + 31 * treatment + x * 3 + rnorm(n_t + n_c, 0, 5)
Y0 <- 10 + 30 * treatment0 + x0 * 3 + rnorm(n_t0 + n_c0, 0, 5)

# Place data into separate treatment and control data frames and
# assign historical = 0 (current) or historical = 1 (historical)
df_ <- data.frame(Y = Y, treatment = treatment, x = x)
df0 <- data.frame(Y = Y0, treatment = treatment0, x = x0)

# Fit model using default settings
fit <- bdplm(
  formula = Y ~ treatment + x, data = df_, data0 = df0,
  method = "fixed"
)

# Look at estimates and discount weight
summary(fit)
print(fit)

Bayesian Discount Prior: Two-Arm Logistic Regression

Description

bdplogit is used to estimate the treatment effect in the presence of covariates using the logistic regression analysis implementation of the Bayesian discount prior. summary and print methods are supported. Currently, the function only supports a two-arm clinical trial where all of current treatment, current control, historical treatment, and historical control data are present

Usage

bdplogit(
  formula = formula,
  data = data,
  data0 = NULL,
  prior_treatment_effect = NULL,
  prior_control_effect = NULL,
  prior_treatment_sd = NULL,
  prior_control_sd = NULL,
  prior_covariate_effect = 0,
  prior_covariate_sd = 10000,
  number_mcmc_alpha = 5000,
  number_mcmc_beta = 10000,
  discount_function = "identity",
  alpha_max = 1,
  fix_alpha = FALSE,
  weibull_scale = 0.135,
  weibull_shape = 3,
  method = "fixed",
  centering = "pooled"
)

Arguments

formula

an object of class "formula." See "Details" for more information, including specification of treatment data indicators.

data

a data frame containing the current data variables in the model. A column named treatment must be present; treatment must be binary and indicate treatment group vs. control group.

data0

a data frame containing the historical data variables in the model. The column labels of data and data0 must match.

prior_treatment_effect

scalar. The historical adjusted treatment effect. If left NULL, value is estimated from the historical data.

prior_control_effect

scalar. The historical adjusted control effect. If left NULL, value is estimated from the historical data.

prior_treatment_sd

scalar. The standard deviation of the historical adjusted treatment effect. If left NULL, value is estimated from the historical data.

prior_control_sd

scalar. The standard deviation of the historical adjusted control effect. If left NULL, value is estimated from the historical data.

prior_covariate_effect

vector. The prior mean(s) of the covariate effect(s). Default value is zero. If a single value is input, the the scalar is repeated to the length of the input covariates. Otherwise, care must be taken to ensure the length of the input matches the number of covariates.

prior_covariate_sd

vector. The prior standard deviation(s) of the covariate effect(s). Default value is 1e4. If a single value is input, the the scalar is repeated to the length of the input covariates. Otherwise, care must be taken to ensure the length of the input matches the number of covariates. Note that covariate effects are intentionally assigned a near-zero historical discount weight, so their priors are effectively flat: the value supplied here has negligible influence on the posterior, and the effective prior standard deviation is much larger than the nominal value (by a factor of roughly 1e6 at the default). In practice the covariate coefficients are estimated almost entirely from the current data, and the posterior is insensitive to this argument across many orders of magnitude.

number_mcmc_alpha

scalar. Number of Monte Carlo simulations for estimating the historical data weight. Default is 5000.

number_mcmc_beta

scalar. Number of Monte Carlo simulations for estimating beta, the vector of regression coefficients. Default is 10000.

discount_function

character. Specify the discount function to use. Currently supports weibull, scaledweibull, and identity. The discount function scaledweibull scales the output of the Weibull CDF to have a max value of 1. The identity discount function uses the posterior probability directly as the discount weight. Default value is "identity".

alpha_max

scalar in [0, 1]. Maximum weight the discount function can apply. Default is 1. Users may specify a vector of two values where the first value is used to weight the historical treatment group and the second value is used to weight the historical control group.

fix_alpha

logical. Fix alpha at alpha_max? Default value is FALSE. If TRUE, comparison models are not fitted and the prescribed weights are used directly. Historical-prior estimation and current-data model checks still apply.

weibull_scale

scalar. Scale parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 0.135. Users may specify a vector of two values where the first value is used to estimate the weight of the historical treatment group and the second value is used to estimate the weight of the historical control group. Not used when discount_function = "identity".

weibull_shape

scalar. Shape parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 3. Users may specify a vector of two values where the first value is used to estimate the weight of the historical treatment group and the second value is used to estimate the weight of the historical control group. Not used when discount_function = "identity".

method

character. Default is "fixed", the only supported method. It estimates each historical weight once and holds it fixed throughout the analysis, unless fix_alpha = TRUE prescribes the weights. An explicit "mc" request is not supported and raises an error.

centering

character. How to center covariates: "pooled" (default) uses current and historical observations, "current" uses current observations only, and "historical" uses historical observations only. "none" leaves covariates unchanged. Each centering mean includes both treatment arms and gives equal weight to each included observation, without discounting. The same means are subtracted from both datasets, including encoded factor covariates. The response and treatment indicator are not centered.

Details

bdplogit uses a two-stage approach for determining the strength of historical data in estimation of an adjusted mean or covariate effect. In the first stage, a discount function is used that defines the maximum strength of the historical data and discounts based on disagreement with the current data. Disagreement between current and historical data is assessed by fitting a logistic regression separately within each arm, with a historical indicator and the covariates, using flat coefficient priors. If q is the posterior probability that the historical-indicator coefficient is positive, the comparison is p = 2\min(q, 1-q). The discount function transforms p into the historical weight alpha. This is not a posterior probability of equality or equivalence.

In the second stage, posterior estimation is performed where the discount function parameter, alpha, is used to weight the historical data effects.

The formula must include an intercept (i.e., do not use -1 in the formula) and both data and data0 must be present. The column names of data and data0 must match. See examples below for example usage.

Formula offsets are not supported. Calls to offset() or stats::offset() cause an error before fitting, including offsets that are zero or cancel each other. Prescribing weights, disabling borrowing, or supplying historical priors does not bypass this restriction.

Internally, the model is parameterized without a fixed intercept, using separate treatment and control (log-odds) means rather than an intercept plus a treatment effect. In this parameterization the arm means are the fitted values at covariate = 0, so when covariates are not centered the treatment- and control-mean estimators can become strongly correlated and their standard errors can reflect extrapolation to covariate = 0. This can affect the discount-prior construction and historical borrowing. To guard against this, bdplogit defaults to centering each covariate at its pooled current and historical mean. The centering argument selects the data used to calculate the mean or disables centering with "none". The reported intercept is transformed back to the original covariate scale. Specifically, if \bar{x}_j is the selected mean of covariate j (or zero under centering = "none") and \beta_j its estimated effect, the reported intercept is \beta_0 = \beta_0^{c} - \sum_j \beta_j \bar{x}_j, where \beta_0^{c} is the control-arm log-odds at the selected covariate reference values. This back-transformation leaves the treatment effect and slopes unchanged; the reported intercept remains the control-arm log-odds at covariate = 0 on the original scale. With mean centering enabled, location shifts of covariates leave the treatment effect and slopes unchanged; the intercept changes with the covariate origin. Centering does not generally make the arm-mean estimators independent, and their covariance is not retained in the diagonal historical prior.

Changing centering can change the estimated treatment effect and its posterior uncertainty, because the independent historical arm priors are constructed at the selected covariate reference values. Transforming the intercept back to the original covariate scale does not remove this dependence. With centering = "none", the historical arm priors refer to covariate = 0, which can involve extrapolation, and results can depend on the covariate origin. User-supplied historical arm-prior means and SDs must describe the adjusted arm log-odds at the selected covariate reference values.

Posterior sampling uses MCMCpack::MCMClogit(). Before fitting, model matrices are checked for rank deficiency, and complete or quasi-complete separation is detected using detectseparation. These checks include separation caused by covariates, as well as groups with no events or with all events. An error identifies the affected stage:

With fix_alpha = TRUE, the comparison models and their checks are skipped; their internal p_hat values are NA_real_. Historical regression checks are skipped only when all four arm-prior means and SDs are supplied. Current-data checks always apply. Prescribing weights alone therefore does not make separated datasets supported.

Use set.seed() before fitting for reproducible sampling. Three distinct seeds are drawn from R's random-number state for the treatment comparison, control comparison, and final fit, and saved in args1$mcmc_seeds. All three are allocated even when prescribed weights skip the comparisons. Different R seeds generate different chains; earlier versions always used MCMCpack's default seed.

Value

bdplogit returns an object of class "bdplm", reusing its print and summary methods. Residual summaries use observed binary outcomes minus fitted probabilities from the posterior mean coefficients. The centering means are saved in args1$covariate_means; older saved fits without these means must be refitted before summarising residuals. The centering choice is saved in args1$centering. Under centering = "none", args1$covariate_means contains zeros because no values are subtracted.

The returned object is a list containing at least the following components:

posterior

data frame. Posterior draws of the intercept, treatment effect, and covariate effects on the log-odds scale.

alpha_discount

data frame. One row of estimated or prescribed historical weights, with columns treatment and control. These weights are not posterior probabilities of equality.

estimates

list. Posterior means and posterior SDs of the intercept, treatment effect, and covariate effects.

Examples

# Set sample sizes
n_t <- 30 # Current treatment sample size
n_c <- 30 # Current control sample size
n_t0 <- 80 # Historical treatment sample size
n_c0 <- 80 # Historical control sample size

# Treatment group vectors for current and historical data
treatment <- c(rep(1, n_t), rep(0, n_c))
treatment0 <- c(rep(1, n_t0), rep(0, n_c0))

# Simulate a covariate effect for current and historical data
x <- rnorm(n_t + n_c, 1, 1)
x0 <- rnorm(n_t0 + n_c0, 1, 1)

# Simulate a binary outcome on the logit scale:
# - Intercept of -1 for current and historical data
# - Treatment (log-odds) effect of 1.0 for current data
# - Treatment (log-odds) effect of 0.9 for historical data
# - Covariate effect of 0.3 for current and historical data
Y <- rbinom(n_t + n_c, 1, plogis(-1 + 1.0 * treatment + 0.3 * x))
Y0 <- rbinom(n_t0 + n_c0, 1, plogis(-1 + 0.9 * treatment0 + 0.3 * x0))

# Place data into separate treatment and control data frames and
# assign historical = 0 (current) or historical = 1 (historical)
df_ <- data.frame(Y = Y, treatment = treatment, x = x)
df0 <- data.frame(Y = Y0, treatment = treatment0, x = x0)

# Fit model using default settings
fit <- bdplogit(
  formula = Y ~ treatment + x, data = df_, data0 = df0,
  method = "fixed"
)

# Look at estimates and discount weight
summary(fit)
print(fit)

Bayesian Discount Prior: Gaussian mean values

Description

bdpnormal is used for estimating posterior samples from a Gaussian outcome where an informative prior is used. The prior weight is determined using a discount function. This code is modeled after the methodologies developed in Haddad et al. (2017).

Usage

bdpnormal(
  mu_t = NULL,
  sigma_t = NULL,
  N_t = NULL,
  mu0_t = NULL,
  sigma0_t = NULL,
  N0_t = NULL,
  mu_c = NULL,
  sigma_c = NULL,
  N_c = NULL,
  mu0_c = NULL,
  sigma0_c = NULL,
  N0_c = NULL,
  discount_function = "identity",
  alpha_max = 1,
  fix_alpha = FALSE,
  weibull_scale = 0.135,
  weibull_shape = 3,
  number_mcmc = 10000,
  method = "mc",
  compare = TRUE
)

Arguments

mu_t

scalar. Mean of the current treatment group.

sigma_t

scalar. Standard deviation of the current treatment group.

N_t

scalar. Number of observations of the current treatment group.

mu0_t

scalar. Mean of the historical treatment group.

sigma0_t

scalar. Standard deviation of the historical treatment group.

N0_t

scalar. Number of observations of the historical treatment group.

mu_c

scalar. Mean of the current control group.

sigma_c

scalar. Standard deviation of the current control group.

N_c

scalar. Number of observations of the current control group.

mu0_c

scalar. Mean of the historical control group.

sigma0_c

scalar. Standard deviation of the historical control group.

N0_c

scalar. Number of observations of the historical control group.

discount_function

character. Specify the discount function to use. Currently supports weibull, scaledweibull, and identity. The discount function scaledweibull scales the output of the Weibull CDF to have a max value of 1. The identity discount function uses the transformed comparison directly as the discount weight. Default value is "identity".

alpha_max

scalar in [0, 1]. Maximum weight the discount function can apply. Default is 1. For a two-arm trial, users may specify a vector of two values where the first value is used to weight the historical treatment group and the second value is used to weight the historical control group.

fix_alpha

logical. Fix alpha at alpha_max? Default value is FALSE.

weibull_scale

scalar. Scale parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 0.135. For a two-arm trial, users may specify a vector of two values where the first value is used to estimate the weight of the historical treatment group and the second value is used to estimate the weight of the historical control group. Not used when discount_function = "identity".

weibull_shape

scalar. Shape parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 3. For a two-arm trial, users may specify a vector of two values where the first value is used to estimate the weight of the historical treatment group and the second value is used to estimate the weight of the historical control group. Not used when discount_function = "identity".

number_mcmc

integer of at least 2. Number of Monte Carlo simulations. Default is 10000.

method

character. Analysis method with respect to estimation of the weight parameter alpha. Default method "mc" estimates alpha for each Monte Carlo iteration, giving a distribution of generated weights. Increasing the number of draws improves numerical precision but does not remove the spread of that distribution. These weights are not draws from a separately specified prior/posterior model for alpha. Alternate value "fixed" estimates alpha once and holds it fixed throughout the analysis. See the bdpnormal vignette
vignette("bdpnormal-vignette", package = "bayesDP") for more details.

compare

logical. Should a comparison object be included in the fit? For a one-arm analysis, the comparison object is simply the posterior draws of the treatment group parameter. For a two-arm analysis, the comparison object is the posterior draws of the treatment effect that compares treatment and control. If compare = TRUE, the comparison object is accessible in the final slot, else the final slot is NULL. Default is TRUE.

Details

Historical borrowing is assessed separately within each arm by comparing population means. With method = "fixed", estimate the probability q that the current mean is below the historical one. The discount input is p = 2 * min(q, 1 - q) and the weight is alpha_max * W(p) for the selected discount function W. This comparison is not a posterior probability of equality or equivalence. Choosing fix_alpha = TRUE prespecifies the weight instead.

Each supplied group requires a scalar finite mean, a positive finite SD, and an integer sample size of at least 2. Zero SDs are not supported by the variance posterior used here. Omit an optional group by leaving all three inputs NULL; zero sample size does not denote an absent group. Inputs and borrowing settings are checked before sampling, including when weights are prescribed. Weibull parameters must be positive and finite when used to estimate a weight.

In the second stage, posterior estimation is performed where the discount function parameter, alpha, is incorporated in all posterior estimation procedures.

To carry out a single arm (OPC) analysis, data for the current treatment (mu_t, sigma_t, and N_t) and historical treatment (mu0_t, sigma0_t, and N0_t) must be input. The results are then based on the posterior distribution of the current data augmented by the historical data.

To carry our a two-arm (RCT) analysis, data for the current treatment and at least one of current or historical control data must be input. The results are then based on the posterior distribution of the difference between current treatment and control, augmented by available historical data.

For more details, see the bdpnormal vignette:
vignette("bdpnormal-vignette", package = "bayesDP")

Value

bdpnormal returns an object of class "bdpnormal". The functions summary and print are used to obtain and print a summary of the results, including user inputs. The plot function displays visual outputs as well.

An object of class bdpnormal is a list containing at least the following components:

posterior_treatment

list. Entries contain values related to the treatment group:

  • alpha_discount numeric. Alpha value, the weighting parameter of the historical data.

  • p_hat numeric. The current-historical comparison between the current and historical data.

  • posterior_mu vector. A vector of length number_mcmc containing the posterior draws of the population mean of the treatment group. If historical treatment data is present, the posterior incorporates the weighted historical data.

  • posterior_sigma2 vector. Conditional variances used to draw the augmented population mean, one per simulation. These are not residual-variance draws or the marginal posterior variance of the mean.

  • posterior_flat_mu vector. A vector of length number_mcmc containing Monte Carlo samples of the mean of the current treatment group under a flat/non-informative prior, i.e., no incorporation of the historical data.

  • posterior_flat_sigma2 vector. A vector of length number_mcmc containing Monte Carlo samples of the residual variance of the current treatment group under a flat/non-informative prior, i.e., no incorporation of the historical data.

  • prior_mu vector. If historical treatment data is present, a vector of length number_mcmc containing Monte Carlo samples of the mean of the historical treatment group under a flat/non-informative prior.

  • prior_sigma2 vector. If historical treatment data is present, a vector of length number_mcmc containing Monte Carlo samples of the residual variance of the historical treatment group under a flat/non-informative prior.

posterior_control

list. Similar entries as posterior_treament. Only present if a control group is specified.

final

list. Contains the final comparison object, dependent on the analysis type:

  • One-arm analysis: vector. Posterior chain of the mean.

  • Two-arm analysis: vector. Posterior chain of the mean difference comparing treatment and control groups.

args1

list. Entries contain user inputs. In addition, the following elements are output:

  • arm2 binary indicator. Used internally to indicate one-arm or two-arm analysis.

  • intent character. Denotes current/historical status of treatment and control groups.

References

Haddad, T., Himes, A., Thompson, L., Irony, T., Nair, R. MDIC Computer Modeling and Simulation working group.(2017) Incorporation of stochastic engineering models as prior information in Bayesian medical device trials. Journal of Biopharmaceutical Statistics, 1-15.

See Also

summary, print, and plot for details of each of the supported methods.

Examples

# One-arm trial (OPC) example
fit <- bdpnormal(
  mu_t = 30, sigma_t = 10, N_t = 50,
  mu0_t = 32, sigma0_t = 10, N0_t = 50,
  method = "fixed"
)
summary(fit)
## Not run: 
plot(fit)

## End(Not run)

# Two-arm (RCT) example
fit2 <- bdpnormal(
  mu_t = 30, sigma_t = 10, N_t = 50,
  mu0_t = 32, sigma0_t = 10, N0_t = 50,
  mu_c = 25, sigma_c = 10, N_c = 50,
  mu0_c = 25, sigma0_c = 10, N0_c = 50,
  method = "fixed"
)
summary(fit2)
## Not run: 
plot(fit2)

## End(Not run)


Bayesian Discount Prior: Survival Analysis

Description

bdpsurvival is used to estimate the survival probability (single arm trial; OPC) or hazard ratio (two-arm trial; RCT) for right-censored data using the survival analysis implementation of the Bayesian discount prior. Current treatment data are required; control data in a two-arm analysis can be current, historical, or both. This code is modeled after the methodologies developed in Haddad et al. (2017).

Usage

bdpsurvival(
  formula = formula,
  data = data,
  data0 = NULL,
  breaks = NULL,
  a0 = 0.1,
  b0 = 0.1,
  surv_time = NULL,
  discount_function = "identity",
  alpha_max = 1,
  fix_alpha = FALSE,
  number_mcmc = 10000,
  weibull_scale = 0.135,
  weibull_shape = 3,
  method = "mc",
  compare = TRUE
)

Arguments

formula

an object of class "formula." Must have a survival object on the left side and at most one input on the right side, treatment. See "Details" for more information. Response expressions such as Surv(followup / 12, status == 1) and survival::Surv() are supported. Only right-censored responses are supported.

data

a data frame containing the current data variables in the model. Supply the variables used in the formula. Evaluated times must be finite and non-negative, with no missing outcomes. If treatment is specified, use numeric 0/1 or logical values, with no missing values; factors and character codes are not converted automatically.

data0

optional. A data frame containing the historical data variables in the model, subject to the same response and treatment checks as current data. It must supply the variables used in the same formula.

breaks

numeric vector. Positive, finite internal cutpoints of the piecewise exponential model, without zero or infinity. Values are sorted and duplicates removed. Use numeric(0) for one constant hazard. Default cutpoints are pooled observed-time quantiles.

a0

positive, finite scalar. Prior value for the gamma shape of the piecewise exponential hazards. Default is 0.1.

b0

positive, finite scalar. Prior value for the gamma rate of the piecewise exponential hazards. Default is 0.1.

surv_time

positive, finite scalar. Time of interest for computing the probability of survival for a single arm (OPC) trial. Default is overall, i.e., current+historical, median observed event-or-censoring time.

discount_function

character. Specify the discount function to use. Currently supports weibull, scaledweibull, and identity. The discount function scaledweibull scales the output of the Weibull CDF to have a max value of 1. The identity discount function uses the transformed comparison directly as the discount weight. Default value is "identity".

alpha_max

scalar in [0, 1]. Maximum weight the discount function can apply. Default is 1. For a two-arm trial, users may specify a vector of two values where the first value is used to weight the historical treatment group and the second value is used to weight the historical control group.

fix_alpha

logical. Fix alpha at alpha_max? Default value is FALSE.

number_mcmc

integer of at least 2. Number of Monte Carlo simulations. Default is 10000.

weibull_scale

scalar. Scale parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 0.135. For a two-arm trial, users may specify a vector of two values where the first value is used to estimate the weight of the historical treatment group and the second value is used to estimate the weight of the historical control group.

weibull_shape

scalar. Shape parameter of the Weibull discount function used to compute alpha, the weight parameter of the historical data. Default value is 3. For a two-arm trial, users may specify a vector of two values where the first value is used to estimate the weight of the historical treatment group and the second value is used to estimate the weight of the historical control group.

method

character. Analysis method with respect to estimation of the weight parameter alpha. Default method "mc" estimates alpha for each Monte Carlo iteration, giving a distribution of generated weights. Increasing the number of draws improves numerical precision but does not remove the spread of that distribution. These weights are not draws from a separately specified prior/posterior model for alpha. Alternate value "fixed" estimates alpha once and holds it fixed throughout the analysis. See the bdpsurvival vignette
vignette("bdpsurvival-vignette", package = "bayesDP") for more details.

compare

logical. Should a comparison object be included in the fit? For a one-arm analysis, the comparison object is simply the posterior draws of the treatment group parameter. For a two-arm analysis, the comparison object is the posterior draws of the treatment effect that compares treatment and control. If compare = TRUE, the comparison object is accessible in the final slot, else the final slot is NULL. Default is TRUE.

Details

Historical borrowing is assessed separately within each arm by comparing survival outcomes. With method = "fixed", estimate a directional probability q comparing current and historical outcomes within an arm. The discount input is p = 2 * min(q, 1 - q) and the weight is alpha_max * W(p) for the selected discount function W. This comparison is not a posterior probability of equality or equivalence. Choosing fix_alpha = TRUE prespecifies the weight instead.

For one arm, q compares survival at surv_time; for two arms it compares current and historical hazards separately within treatment and control using analytic inverse-variance weights for the interval log hazard differences. With method = "mc", each draw's difference is divided by its posterior standard deviation and mapped to 2 * pnorm(abs(Z), lower.tail = FALSE). The variance is calculated from exact Gamma moments: hazard variances for log survival differences, and trigamma log-hazard variances for two-arm comparisons. The normal-tail mapping remains an approximation, especially with sparse events. The returned p_hat uses the selected method's transformation even with fix_alpha = TRUE; the prescribed weight is unaffected.

In the second stage, the historical likelihood is raised to the weight alpha, and the baseline Gamma prior is included once. For an interval with current event count D and exposure T, and historical event count D0 and exposure T0, the augmented Gamma shape and rate are a0 + D + alpha * D0 and b0 + T + alpha * T0. The prior shape a0 is distinct from the historical weight alpha. At alpha = 0 this gives the current-only posterior; at alpha = 1 it gives the pooled posterior using the same interval boundaries and baseline prior. With method = "mc", each draw uses its generated weight; the resulting marginal distribution is a mixture of Gamma distributions.

To carry out a single arm (OPC) analysis, data for the current and historical treatments are specified in separate data frames, data and data0, respectively. The formula is evaluated separately in each data frame to obtain the survival (censor) time and event indicator. Missing outcomes or treatment values cause an error rather than dropping rows. Counting-process, interval-censored, and multistate responses are not supported. The results are then based on the posterior probability of survival at surv_time for the current data augmented by the historical data.

Two-arm (RCT) analyses use the same response specification, with an additional column named 'treatment' to denote treatment and control data. Use 1 (or TRUE) for treatment and 0 (or FALSE) for control in each data frame. The current data are augmented by historical data (if present) and the results are then based on the posterior distribution of the hazard ratio between the treatment and control groups.

For more details, see the bdpsurvival vignette:
vignette("bdpsurvival-vignette", package = "bayesDP")

Value

bdpsurvival returns an object of class "bdpsurvival". The functions summary and print are used to obtain and print a summary of the results, including user inputs. The plot function displays visual outputs as well.

An object of class "bdpsurvival" is a list containing at least the following components:

posterior_treatment

list. Entries contain values related to the treatment group:

  • alpha_discount numeric. Alpha value, the weighting parameter of the historical data.

  • p_hat numeric. The two-sided current-historical comparison in [0, 1]: one value for method = "fixed", or number_mcmc values for method = "mc". See Details for the transformation.

  • posterior_survival matrix. If one-arm trial, one column with number_mcmc rows containing the posterior probability draws of survival at surv_time.

  • posterior_flat_survival matrix. If one-arm trial, one column with number_mcmc rows containing the probability draws of survival at surv_time for the current treatment not augmented by historical treatment.

  • prior_survival matrix. If one-arm trial, one column with number_mcmc rows containing the probability draws of survival at surv_time for the historical treatment.

  • posterior_hazard matrix. A matrix with number_mcmc rows and length(breaks) + 1 columns containing the posterior draws of the piecewise hazards for each interval break point.

  • posterior_flat_hazard matrix. A matrix with number_mcmc rows and length(breaks) + 1 columns containing the draws of piecewise hazards for each interval break point for current treatment not augmented by historical treatment.

  • prior_hazard matrix. A matrix with number_mcmc rows and length(breaks) + 1 columns containing the draws of piecewise hazards for each interval break point for historical treatment.

  • posterior_log_hazard, posterior_flat_log_hazard, prior_log_hazard matrices. Log hazards corresponding to the three hazard matrices. These retain finite log draws when very small hazards round to zero and are used for borrowing comparisons and the two-arm effect.

posterior_control

list. If two-arm trial, contains values related to the control group analogous to the posterior_treatment output.

final

list. Contains the final comparison object, dependent on the analysis type:

  • One-arm analysis: vector. Posterior chain of survival probability at requested time.

  • Two-arm analysis: vector. Posterior chain of log-hazard rate comparing treatment and control groups.

args1

list. Entries contain user inputs. In addition, the following elements are output:

  • S_t, S_c, S0_t, S0_c survival objects. Used internally to pass survival data between functions.

  • arm2 logical. Used internally to indicate one-arm or two-arm analysis.

  • participants data frame. One record per participant, with observed time, event status, treatment, and historical source. Used for reported sample sizes and risk sets; data contains the split interval records used for hazard estimation.

References

Haddad, T., Himes, A., Thompson, L., Irony, T., Nair, R. MDIC Computer Modeling and Simulation working group.(2017) Incorporation of stochastic engineering models as prior information in Bayesian medical device trials. Journal of Biopharmaceutical Statistics, 1-15.

See Also

summary, print, and plot for details of each of the supported methods.

Examples

# One-arm trial (OPC) example - survival probability at 5 years

# Collect data into data frames
df_ <- data.frame(
  status = rexp(50, rate = 1 / 30),
  time = rexp(50, rate = 1 / 20)
)
df_$status <- ifelse(df_$time < df_$status, 1, 0)

df0 <- data.frame(
  status = rexp(50, rate = 1 / 30),
  time = rexp(50, rate = 1 / 10)
)
df0$status <- ifelse(df0$time < df0$status, 1, 0)


fit1 <- bdpsurvival(Surv(time, status) ~ 1,
  data = df_,
  data0 = df0,
  surv_time = 5,
  method = "fixed"
)

print(fit1)
## Not run: 
plot(fit1)

## End(Not run)

# Two-arm trial example
# Collect data into data frames
df_ <- data.frame(
  time = c(
    rexp(50, rate = 1 / 20), # Current treatment
    rexp(50, rate = 1 / 10)
  ), # Current control
  status = rexp(100, rate = 1 / 40),
  treatment = c(rep(1, 50), rep(0, 50))
)
df_$status <- ifelse(df_$time < df_$status, 1, 0)

df0 <- data.frame(
  time = c(
    rexp(50, rate = 1 / 30), # Historical treatment
    rexp(50, rate = 1 / 5)
  ), # Historical control
  status = rexp(100, rate = 1 / 40),
  treatment = c(rep(1, 50), rep(0, 50))
)
df0$status <- ifelse(df0$time < df0$status, 1, 0)

fit2 <- bdpsurvival(Surv(time, status) ~ treatment,
  data = df_,
  data0 = df0,
  method = "fixed"
)
summary(fit2)

### Fix alpha at 1
fit2_1 <- bdpsurvival(Surv(time, status) ~ treatment,
  data = df_,
  data0 = df0,
  fix_alpha = TRUE,
  method = "fixed"
)
summary(fit2_1)

Glance at a Bayesian discount prior fit

Description

Return sample sizes, retained draw counts, and historical discount weights in a one-row tibble. These methods also work with broom::glance().

Usage

glance(x, ...)

## S3 method for class 'bdpbinomial'
glance(x, ...)

## S3 method for class 'bdpnormal'
glance(x, ...)

## S3 method for class 'bdplm'
glance(x, ...)

## S3 method for class 'bdpsurvival'
glance(x, ...)

Arguments

x

A fitted bdpbinomial, bdpnormal, bdplm, or bdpsurvival object. Fits from bdplogit() use class bdplm.

...

The table-formatting argument gof_map and coefficient-summary arguments exponentiate, effects, and time are accepted but do not affect model-level summaries. This allows modelsummary to forward them to both tidy() and glance(). Other arguments produce an error.

Details

Survival sample sizes and event counts use the saved participant records, not the rows created by splitting follow-up into hazard intervals. For older survival fits without participant records, these counts are NA; refit to obtain them. The columns and their order are fixed within each fitted class. No likelihood criteria, convergence diagnostics, or posterior comparison probabilities are supplied.

Value

A one-row tibble containing:

nobs

Number of current participants included in the analysis, summed across arms.

n.historical

Number of historical participants included in the analysis, summed across arms. Historical-only controls are counted here, not in nobs. An absent source contributes zero. These are unweighted counts, not effective sample sizes.

n.draws

Number of retained outcome posterior draws, counted from the saved draws rather than the requested simulation size. This is not a simulation effective sample size.

alpha.treatment, alpha.control

Median stored historical discount weight for each arm. A prescribed or estimated fixed weight is returned unchanged. NA indicates that a weight is not defined, including historical-only controls and absent arms or historical sources.

n.event, n.event.historical

For survival fits only, numbers of observed events among current and historical participants, respectively.

Author(s)

Graeme L. Hickey

See Also

tidy

Examples

set.seed(42)
fit <- bdpnormal(mu_t = 3, sigma_t = 2, N_t = 40,
  mu0_t = 2.8, sigma0_t = 2, N0_t = 60,
  method = "fixed", number_mcmc = 1000)
glance(fit)

Count current participants

Description

Return the number of current participants included in a fitted analysis.

Usage

## S3 method for class 'bdpbinomial'
nobs(object, ...)

## S3 method for class 'bdpnormal'
nobs(object, ...)

## S3 method for class 'bdplm'
nobs(object, ...)

## S3 method for class 'bdpsurvival'
nobs(object, ...)

Arguments

object

A fitted bdpbinomial, bdpnormal, bdplm, or bdpsurvival object. Fits from bdplogit() use class bdplm.

...

Additional arguments are not supported and produce an error.

Details

Historical participants, including historical-only controls, are excluded. These are unweighted participant counts, not effective sample sizes. Survival counts use original participant records rather than split follow-up intervals. For older survival or regression fits without the necessary records, the result is NA. Use glance() to obtain historical counts separately.

Value

A single numeric count, matching the nobs column of glance(object).

Author(s)

Graeme L. Hickey

See Also

glance

Examples

set.seed(42)
fit <- bdpbinomial(y_t = 8, N_t = 40, y0_t = 12, N0_t = 60,
  method = "fixed", number_mcmc = 100)
nobs(fit)
glance(fit)

bdpbinomial Object Plot

Description

plot method for class bdpbinomial.

Usage

## S4 method for signature 'bdpbinomial'
plot(x, type = NULL, print = TRUE)

Arguments

x

object of class bdpbinomial. The result of a call to the bdpbinomial function.

type

character. Optional. Select plot type to print. Supports the following: "discount" gives the discount function; "posteriors" gives the posterior distributions by information source; "density" gives the augmented arm distributions; and "effect" gives the treatment-minus-control difference for a two-arm analysis. Leave NULL to display the first three plots in sequence.

print

logical. Optional. Produce a plot (print = TRUE; default) or return a ggplot object (print = FALSE). When print = FALSE, it is possible to use ggplot2 syntax to modify the plot appearance.

Details

The plot method for bdpbinomial returns up to three plots: (1) posterior density curves by information source; (2) augmented arm densities; and (3) the discount function. A call to plot that omits the type input returns one plot at a time and prompts the user to click the plot or press return to proceed to the next plot. Otherwise, the user can specify a plot type to display the requested plot.


bdpnormal Object Plot

Description

plot method for class bdpnormal.

Usage

## S4 method for signature 'bdpnormal'
plot(x, type = NULL, print = TRUE)

Arguments

x

object of class bdpnormal. The result of a call to the bdpnormal function.

type

character. Optional. Select plot type to print. Supports the following: "discount" gives the discount function; "posteriors" gives the posterior distributions by information source; "density" gives the augmented arm distributions; and "effect" gives the treatment-minus-control difference for a two-arm analysis. Leave NULL to display the first three plots in sequence.

print

logical. Optional. Produce a plot (print = TRUE; default) or return a ggplot object (print = FALSE). When print = FALSE, it is possible to use ggplot2 syntax to modify the plot appearance.

Details

The plot method for bdpnormal returns up to three plots: (1) posterior density curves by information source; (2) augmented arm densities; and (3) the discount function. A call to plot that omits the type input returns one plot at a time and prompts the user to click the plot or press return to proceed to the next plot. Otherwise, the user can specify a plot type to display the requested plot.


bdpsurvival Object Plot

Description

plot method for class bdpsurvival.

Usage

## S4 method for signature 'bdpsurvival'
plot(x, type = NULL, print = TRUE)

Arguments

x

object of class bdpsurvival. The result of a call to the bdpsurvival function.

type

character. Optional. Select plot type to print. Supports the following: "discount" gives the discount function and "survival" gives the survival curves. Leave NULL to display all plots in sequence.

print

logical. Optional. Produce a plot (print = TRUE; default) or return a ggplot object (print = FALSE). When print = FALSE, it is possible to use ggplot2 syntax to modify the plot appearance.

Details

The plot method for bdpsurvival returns up to two plots: (1) posterior survival curves and (2) the discount function. A call to plot that omits the type input returns one plot at a time and prompts the user to click the plot or press return to proceed to the next plot. Otherwise, the user can specify a plot type to display the requested plot.


Convert saved posterior draws

Description

Use posterior::as_draws_df() or posterior::as_draws_matrix() to extract saved draws in a standard format for posterior calculations and plotting. The optional posterior package must be installed.

Usage

## S3 method for class 'bdpbinomial'
as_draws_matrix(x, ...)

## S3 method for class 'bdpnormal'
as_draws_matrix(x, ...)

## S3 method for class 'bdplm'
as_draws_matrix(x, ...)

## S3 method for class 'bdpsurvival'
as_draws_matrix(x, ...)

## S3 method for class 'bdpbinomial'
as_draws_df(x, ...)

## S3 method for class 'bdpnormal'
as_draws_df(x, ...)

## S3 method for class 'bdplm'
as_draws_df(x, ...)

## S3 method for class 'bdpsurvival'
as_draws_df(x, ...)

Arguments

x

A fitted bdpbinomial, bdpnormal, bdplm, or bdpsurvival object. Fits from bdplogit() use class bdplm.

...

Additional arguments are not supported and produce an error.

Details

Conversion preserves the order and number of saved draws and does not refit, resample, or alter R's random-number state. Variable definitions are:

Binomial and normal fits

treatment, then control and difference when a control arm is present. These are event probabilities or population means and their paired treatment-minus-control differences, including historical-only controls and fits with compare = FALSE. The conditional mean variances stored by normal fits are not included: they are not residual-variance draws.

Regression fits

The intercept (Intercept), treatment effect, and covariate coefficients on the original covariate scale. Logistic coefficients are on the log-odds scale. Linear fits additionally include the residual SD sigma.

Survival fits

Interval log hazards named log_hazard_treatment[1], log_hazard_treatment[2], and so on, with corresponding log_hazard_control[j] columns when a control arm is present. Interval order follows x$args1$breaks. One-arm fits also include survival, the survival probability at x$args1$surv_time; two-arm fits include treatment, the approximate common log hazard ratio reported by tidy(). This summary does not impose proportional hazards. Older fits without saved log hazards use the logarithms of their stored hazards.

Discount weights, comparison probabilities, and separate prior or current-only draws are not included.

The draws are represented as one sequence (.chain = 1), with consecutive .iteration and .draw indices. These indices describe retained row order, not the original iteration numbers before burn-in or thinning. Logistic fits contain a single retained MCMC sequence; the other fits contain Monte Carlo draws from the package's sampling calculations. Conversion does not create independent chains or establish convergence. In particular, splitting these rows into artificial chains is not a substitute for independent fits when assessing convergence.

Value

A posterior::draws_df or posterior::draws_matrix object, with one row per retained draw. The data-frame format includes .chain, .iteration, and .draw metadata columns.

Author(s)

Graeme L. Hickey

See Also

tidy, regression_extractors

Examples

if (requireNamespace("posterior", quietly = TRUE)) {
  set.seed(42)
  fit <- bdpbinomial(y_t = 8, N_t = 40, y_c = 5, N_c = 40,
    y0_t = 10, N0_t = 50, y0_c = 8, N0_c = 50,
    method = "fixed", number_mcmc = 100)
  draws <- posterior::as_draws_df(fit)
  mean(draws$difference > 0)
  posterior::as_draws_matrix(fit)
}

Compute cdf of the piecewise exponential distribution

Description

ppexp is used to compute the cumulative distribution function of the piecewise exponential distribution. The function is ported from R to C++ via code adapted from the msm package.

Usage

ppexp(q, x, cuts)

Arguments

q

scalar. The time point at which the cdf is to be computed.

x

vector or matrix. The hazard rate(s).

cuts

vector. Times at which the rate changes, i.e., the interval cut points. The first element of cuts should be 0, and cuts should be in increasing order. Must be the same length as x (vector) or have the same number of columns as x (matrix)

Details

The code underlying ppexp is written in C++ and adapted from R code used in the msm package.

Value

The cumulative distribution function computed at time q, hazard(s) x, and cut points cuts.

Examples

# Single vector of hazard rates. Returns a single cdf value.
q <- 12
x <- c(0.25, 0.3, 0.35, 0.4)
cuts <- c(0, 6, 12, 18)
pp <- ppexp(q, x, cuts)

# Matrix of multiple vectors of hazard rates. Returns 10 cdf values.
x <- matrix(rgamma(4 * 10, 0.1, 0.1), nrow = 10)
pp <- ppexp(q, x, cuts)

bdpbinomial Object Print

Description

print method for class bdpbinomial.

Usage

## S4 method for signature 'bdpbinomial'
print(x)

Arguments

x

object of class bdpbinomial. The result of a call to the bdpbinomial function.

Details

Returns same output as a call to summary.


bdplm Object Print

Description

print method for class bdplm.

Usage

## S4 method for signature 'bdplm'
print(x)

Arguments

x

object of class bdplm. The result of a call to the bdplm function.

Details

Displays a print of the bdplm fit and the initial function call. The fit includes the estimate of the intercept, treatment effect, and covariate effects. The discount function weight estimates are displayed as well. If method = "mc", the median estimate of alpha is displayed.


bdpnormal Object Print

Description

print method for class bdpnormal.

Usage

## S4 method for signature 'bdpnormal'
print(x)

Arguments

x

object of class bdpnormal. The result of a call to the bdpnormal function.

Details

Returns same output as a call to summary.


bdpsurvival Object Print

Description

print method for class bdpsurvival.

Usage

## S4 method for signature 'bdpsurvival'
print(x)

Arguments

x

object of class bdpsurvival. The result of a call to the bdpsurvival function.

Details

Displays a print of the bdpsurvival fit. The output is different, conditional on a one- or two-arm survival analysis.

In the case of a one-arm analysis, a brief summary is displayed, including the current data sample size, number of events, user input survival time, the augmented median survival probability, and corresponding lower and upper 95 percent equal-tailed credible limits. Counts use participant-level records. Saved fits without these records must be refitted before printing.

When a control arm is present, the output is the same as a call to summary.


Bayesian Discount Prior: Comparison Between Current and Historical Data

Description

An educational calculation of the current-historical comparison for normal summary data. This helper is not used internally. The fixed method returns twice the smaller directional posterior probability; the Monte Carlo method returns a normal-tail comparison for each draw.

Usage

probability_discount(
  mu = NULL,
  sigma = NULL,
  N = NULL,
  mu0 = NULL,
  sigma0 = NULL,
  N0 = NULL,
  number_mcmc = 10000,
  method = "fixed"
)

Arguments

mu

scalar. Mean of the current data.

sigma

scalar. Standard deviation of the current data.

N

scalar. Number of observations of the current data.

mu0

scalar. Mean of the historical data.

sigma0

scalar. Standard deviation of the historical data.

N0

scalar. Number of observations of the historical data.

number_mcmc

scalar. Number of Monte Carlo simulations. Default is 10000.

method

character. Default "fixed" estimates a directional probability q and returns 2 * min(q, 1 - q). With "mc", each pair of mean draws is standardized by its conditional standard error and converted to a two-sided normal-tail comparison. See the normal vignette for details.

Details

This is a borrowing comparison, not a posterior probability of equality or equivalence. Weight variation under "mc" is part of that procedure; more draws improve the precision of its distributional summaries. The baseline prior for each source is proportional to 1 / \sigma^2. The fixed method uses direct Monte Carlo simulation.

Value

A numeric comparison in [0, 1]: one value under "fixed", or a vector of length number_mcmc under "mc".

References

Haddad, T., Himes, A., Thompson, L., Irony, T., Nair, R. MDIC Computer Modeling and Simulation working group.(2017) Incorporation of stochastic engineering models as prior information in Bayesian medical device trials. Journal of Biopharmaceutical Statistics, 1-15.

Examples

probability_discount(
  mu = 0, sigma = 1, N = 100,
  mu0 = 0.1, sigma0 = 1, N0 = 100
)

Extract regression estimates and credible intervals

Description

Extract posterior summaries from linear and logistic regression fits without refitting or drawing new samples.

Usage

## S3 method for class 'bdplm'
coef(object, ...)

## S3 method for class 'bdplm'
vcov(object, complete = TRUE, ...)

## S3 method for class 'bdplm'
confint(object, parm, level = 0.95, ...)

Arguments

object

A fit from bdplm or bdplogit. Both use class bdplm.

...

Additional arguments are not supported and produce an error.

complete

Logical, for compatibility with stats::vcov(). Both values return the same matrix because these fits do not contain aliased coefficients.

parm

Coefficient names or positive integer positions. Defaults to all coefficients.

level

Credible interval probability, strictly between zero and one.

Details

Coefficients are posterior means on the original covariate scale, with the intercept named (Intercept). Logistic coefficients remain on the log-odds scale. The residual SD sigma is excluded; use tidy(object, effects = "sigma") for that parameter in a linear model.

Despite the conventional function names, confint() returns equal-tailed posterior credible intervals, using stats::quantile() with its default interpolation. vcov() returns the sample covariance of the saved coefficient draws, including their posterior correlations. It is neither a frequentist sampling covariance nor the Monte Carlo covariance of the estimated posterior means.

Value

coef() returns a named numeric vector; vcov() returns a square matrix with matching coefficient names; confint() returns a matrix with one row per selected coefficient and two columns giving the lower and upper posterior quantiles.

Author(s)

Graeme L. Hickey

See Also

tidy, posterior_draws, nobs.bdpbinomial

Examples

set.seed(42)
current <- data.frame(treatment = rep(0:1, each = 20))
current$y <- 2 + current$treatment + rnorm(40)
historical <- current
historical$y <- 2 + historical$treatment + rnorm(40)
fit <- bdplm(y ~ treatment, data = current, data0 = historical,
  method = "fixed", number_mcmc_alpha = 100,
  number_mcmc_sigmagrid = 100, number_mcmc_sigma = 50,
  number_mcmc_beta = 200)
coef(fit)
vcov(fit)
confint(fit, parm = "treatment", level = 0.9)

bdpbinomial Object Summary

Description

summary method for class bdpbinomial.

Usage

## S4 method for signature 'bdpbinomial'
summary(object)

Arguments

object

object of class bdpbinomial. The result of a call to the bdpbinomial function.

Details

Displays input data, the current-historical comparison, and historical weights when both sources are available. Under method = "mc", the comparison and weight summaries are medians across draws. The outcome estimates are posterior medians of each arm's event probability. Intervals are the 2.5th and 97.5th posterior percentiles. For a two-arm analysis, the interval describes the treatment-minus-control difference, calculated from paired draws. It is not a confidence interval or a test of equality. Printed estimates retain four decimal places.


bdplm Object Summary

Description

summary method for class bdplm.

Usage

## S4 method for signature 'bdplm'
summary(object)

Arguments

object

an object of class bdplm, a result of a call to bdplm.

Details

Displays a summary of the bdplm fit. Displayed output is similar to summary.lm. The function call, residuals, and coefficient table are displayed. The discount function weight estimates are displayed as well. If method = "mc", the median estimate of alpha is displayed. Residuals use current outcomes minus predictions from posterior mean coefficients, with covariates and intercept on the original scale. The method is also used by bdplogit(); for those fits, residuals are observed binary outcomes minus fitted probabilities obtained by applying the inverse logit to the posterior mean linear predictor. Saved fits without the covariate centering means must be refitted before calling summary().


bdpnormal Object Summary

Description

summary method for class bdpnormal.

Usage

## S4 method for signature 'bdpnormal'
summary(object)

Arguments

object

object of class bdpnormal. The result of a call to the bdpnormal function.

Details

Displays input data, the current-historical comparison, and historical weights when both sources are available. Under method = "mc", the comparison and weight summaries are medians across draws. The outcome estimates are posterior medians of each arm's population mean. Intervals are the 2.5th and 97.5th posterior percentiles. For a two-arm analysis, the interval describes the treatment-minus-control difference, calculated from paired draws. It is not a confidence interval or a test of equality. Printed estimates retain four decimal places.


bdpsurvival Object Summary

Description

summary method for class bdpsurvival.

Usage

## S4 method for signature 'bdpsurvival'
summary(object)

Arguments

object

an object of class bdpsurvival, a result of a call to bdpsurvival.

Details

Displays a summary of the bdpsurvival fit. The output is different, conditional on a one- or two-arm survival analysis.

In the case of a one-arm analysis, the stochastic comparison between current and historical data and the resulting historical data weight (alpha) are displayed, followed by a survival table containing augmented posterior estimates of the survival probability at each time point for the current data. Times are observed event or censoring times. Risk sets and event counts describe current participants, not the split hazard intervals. The survival estimates are posterior medians, with posterior SDs and 95 equal-tailed credible intervals; they are not Kaplan–Meier estimates. Saved fits without participant-level records must be refitted before calling summary().

When a control arm is present, the summary describes the approximate common log hazard ratio from the piecewise hazard draws. The comparison between current and historical data and the resulting historical data weight (alpha) are displayed, when historical data is present for the respective arm. The displayed coef is the posterior mean log hazard ratio, treatment relative to control; exp(coef) exponentiates this mean, and se(coef) is its posterior SD. The 95 percent equal-tailed credible limits are on the log hazard ratio scale. Sample sizes and event counts describe the current arms, or historical controls when current controls are absent.


Tidy posterior summaries

Description

Summarise saved posterior draws in a tibble, without refitting or drawing new samples. These methods also work with broom::tidy().

Usage

tidy(x, ...)

## S3 method for class 'bdpbinomial'
tidy(x, conf.int = FALSE, conf.level = 0.95, ...)

## S3 method for class 'bdpnormal'
tidy(x, conf.int = FALSE, conf.level = 0.95, ...)

## S3 method for class 'bdplm'
tidy(
  x,
  conf.int = FALSE,
  conf.level = 0.95,
  exponentiate = FALSE,
  effects = c("coefficients", "sigma"),
  ...
)

## S3 method for class 'bdpsurvival'
tidy(
  x,
  conf.int = FALSE,
  conf.level = 0.95,
  exponentiate = FALSE,
  time = x$args1$surv_time,
  ...
)

Arguments

x

A fitted bdpbinomial, bdpnormal, bdplm, or bdpsurvival object. Fits from bdplogit() use class bdplm.

...

Unrecognised arguments produce an error. The neutral arguments vcov = NULL and coef_rename = FALSE, forwarded by modelsummary, are accepted. Rename table terms with modelsummary(..., coef_map = ...); covariance overrides are not supported because uncertainty is calculated from posterior draws.

conf.int

Logical; include equal-tailed credible limits? Defaults to FALSE.

conf.level

Credible interval probability, strictly between zero and one. Defaults to 0.95.

exponentiate

Logical; exponentiate logistic coefficients or the two-arm survival effect? Defaults to FALSE. Not supported for other quantities.

effects

For regression fits, "coefficients" returns the intercept, treatment effect, and covariate coefficients; "sigma" returns the residual SD of a linear model. Logistic fits have no residual SD parameter.

time

For a one-arm survival fit, a single finite, nonnegative time at which to summarise survival. Defaults to the fit's surv_time. Cannot be supplied for a two-arm fit.

Details

Binomial and normal fits return treatment, then control and difference when a control arm is present. These describe event probabilities or population means, and the treatment-minus-control difference. Estimates are posterior medians. Differences are calculated from paired draws, including when controls are historical only or the fit used compare = FALSE.

Regression fits return posterior means on the original covariate scale, with the intercept named (Intercept). Logistic coefficients are on the log-odds scale unless exponentiate = TRUE.

One-arm survival fits return a survival row containing the posterior median survival probability and a time column. Two-arm fits return a treatment row for the approximate common log hazard ratio, treatment relative to control, with time = NA. Its estimate is the posterior mean of the inverse-variance-weighted interval log hazard ratio draws used by summary(); it is not a time-specific hazard ratio or an assumption of proportional hazards.

With exponentiate = TRUE, the estimate is the exponential of the posterior mean log effect, not the posterior mean odds ratio or hazard ratio. Credible limits are exponentiated log-scale quantiles. The std.error column is the SD of the exponentiated draws, so it is on the reported ratio scale, not the log scale or a delta-method approximation. For an exponentiated logistic intercept, the estimate describes baseline odds.

Value

A tibble with one row per quantity and columns term, estimate, and std.error. Despite its conventional name, std.error is a posterior SD, not a frequentist standard error or Monte Carlo standard error. If conf.int = TRUE, conf.low and conf.high contain equal-tailed credible limits, computed using stats::quantile() with its default interpolation. Survival results also contain time. Results retain full numerical precision. No test statistics or p-values are reported.

Author(s)

Graeme L. Hickey

See Also

glance, summary

Examples

set.seed(42)
fit <- bdpbinomial(y_t = 8, N_t = 40, y_c = 5, N_c = 40,
  y0_t = 10, N0_t = 50, y0_c = 8, N0_c = 50,
  method = "fixed", number_mcmc = 1000)
tidy(fit, conf.int = TRUE)
glance(fit)