BayesDP

Introduction

The purpose of this vignette is to introduce the bdplm function. bdplm is used for estimating posterior samples in the context of linear regression for clinical trials where an informative prior is used. In the parlance of clinical trials, the informative prior is derived from historical data. The weight given to the historical data is determined using what we refer to as a discount function. There are three steps in carrying out estimation:

  1. Estimation of the historical data weight, denoted α̂, via the discount function

  2. Estimation of the posterior distribution of the current data, conditional on the historical data weighted by α̂

  3. Estimation of the posterior treatment effect, i.e., treatment versus control

Throughout this vignette, we use the terms current, historical, treatment, and control. These terms are used because the model was envisioned in the context of clinical trials where historical data may be present. Because of this terminology, there are 4 potential sources of data:

  1. Current treatment data: treatment data from a current study

  2. Current control data: control (or other treatment) data from a current study

  3. Historical treatment data: treatment data from a previous study

  4. Historical control data: control (or other treatment) data from a previous study

If only treatment data is input, the function considers the analysis a one-arm trial. If treatment data + control data is input, then it is considered a two-arm trial.

Note that the bdplm function currently only has support for a two-arm clinical trial where current and historical treatment and current and historical control data are all present.

Linear Regresion Model Background

Before we get into our estimation scheme, we will briefly describe our implementation of the linear regression model. The linear regression model implementation, via bdplm, serves as an advanced companion to the bdpnormal model. With the bdpnormal model, we are interested in comparing mean outcomes via the probability that the mean values from treatment and control arms are not equivalent. When covariate adjustments are needed, bdpnormal is no longer a viable solution. Thus, bdplm allows analysts to adjust the treatment and control arm comparison for covariate effects.

The analysis model of interest has the form yi = β0 + β1I(treatmenti) + x2iβ2 + ⋯ + xmiβm + εi, εi ∼ 𝒩ormal(0, σ2),   i = 1, …, n, where I(treatmenti) indicates whether observation i is in the treatment arm, β0 is the intercept, β1 is the treatment effect, xji is the jth covariate with corresponding βj covariate effect, j = 2, …, m, and σ2 is the unknown error variance.

Let xiTβ−(0, 1) = x2iβ2 + ⋯ + xmiβm. Then, in order to place prior values on the treatment effect, we reparameterize the linear regression model as yi = β0*I(controli) + β1*I(treatmenti) + xiTβ−(0, 1) + εi, εi ∼ 𝒩ormal(0, σ2),   i = 1, …, n, where now I(controli) indicates whether observation i is in the control arm, i.e., I(controli) = 1 − I(treatmenti). It is then straightforward to show that β0 = β0* and β1 = β1* − β0*.

Estimation of the historical data weight

In the first estimation step, the historical data weight α̂ is estimated. In the case of a two-arm trial, where both treatment and control data are available, an α̂ value is estimated separately for each of the treatment and control arms. Of course, historical treatment or historical control data must be present, otherwise α̂ is not estimated for the corresponding arm.

When historical data are available, estimation of α̂ is carried out as follows. Let y and y0 denote the current and historical data, respectively. The following linear regression model is then fit to the data: yi = β̃0 + β̃1I(historicali) + x2iβ̃2 + ⋯ + xmiβ̃m + εi, εi ∼ 𝒩ormal(0, σ2),   i = 1, …, n, where I(historicali) indicates whether observation i is historical. With vague priors on each parameter, we estimate the posterior probability that β̃1 > 0 by first computing $p_1 = Pr\left(\tilde{\beta_1} > 0 \mid \boldsymbol{y}, \boldsymbol{y}_0\right)$. Then, we calculate the posterior probability p as

$$ p=\begin{cases} 2p_{1}, & p_{1}\le0.5\\ 2\left(1-p_{1}\right), & p_{1}>0.5. \end{cases} $$

Finally, for a discount function, denoted W, α̂ is computed as α̂ = αmax ⋅ W(p, w), 0 ≤ p ≤ 1, where w may be one or more parameters associated with the discount function and αmax scales the weight α̂ by a user-input maximum value. More details on the discount functions are given in the discount function section below.

There are several model inputs at this first stage. First, the user can select fix_alpha=TRUE and force a fixed value of α̂ (at the alpha_max input), as opposed to estimation via the discount function.

An alternate Monte Carlo-based estimation scheme of α̂ has been implemented, controlled by the function input method="mc". Here, instead of treating α̂ as a fixed quantity, α̂ is treated as random. First, p, is computed as

$$ \begin{array}{rcl} Z & = & \displaystyle{\frac{\left|\beta_1\right|}{\sigma_{\beta}}},\\ \\ p & = & 2\left(1-\Phi\left(Z\right)\right), \end{array} $$ where σβ is an estimate of the standard deviation of β1 and Φ(x) is the xth quantile of a standard normal (i.e., the pnorm R function). Next, p is used to construct α̂ via the discount function. Since the values Z and p are computed at each iteration of the Monte Carlo estimation scheme, α̂ is computed at each iteration of the Monte Carlo estimation scheme, resulting in a distribution of α̂ values.

Discount function

There are currently three discount functions implemented throughout the bayesDP package. The discount function is specified using the discount_function input with the following choices available:

  1. identity (default): Identity.

  2. weibull: Weibull cumulative distribution function (CDF);

  3. scaledweibull: Scaled Weibull CDF;

First, the identity discount function (default) sets the discount weight α̂ = p.

Second, the Weibull CDF has two user-specified parameters associated with it, the shape and scale. The default shape is 3 and the default scale is 0.135, each of which are controlled by the function inputs weibull_shape and weibull_scale, respectively. The form of the Weibull CDF is W(x) = 1 − exp {−(x/wscale)wshape}.

The third discount function option is the Scaled Weibull CDF. The Scaled Weibull CDF is the Weibull CDF divided by the value of the Weibull CDF evaluated at 1, i.e., W*(x) = W(x)/W(1). Similar to the Weibull CDF, the Scaled Weibull CDF has two user-specified parameters associated with it, the shape and scale, again controlled by the function inputs weibull_shape and weibull_scale, respectively.

Using the default shape and scale inputs, each of the discount functions are shown below.

In each of the above plots, the x-axis is the stochastic comparison between current and historical data, which we’ve denoted p. The y-axis is the discount value α̂ that corresponds to a given value of p.

An advanced input for the plot function is print. The default value is print = TRUE, which simply returns the graphics. Alternately, users can specify print = FALSE, which returns a ggplot2 object. Below is an example using the discount function plot:

p1 <- plot(fit02, type="discount", print=FALSE)
p1 + ggtitle("Discount Function Plot :-)")

Estimation of the posterior distribution of the current data, conditional on the historical data

This section details the modeling scheme used to estimate the parameters of the linear regression model. In vector notation the model can be written $$ \begin{array}{rcl} \mathbf{y} & \sim & \mathcal{N}\left(\mathbf{X}\boldsymbol{\beta},\thinspace\boldsymbol{\Sigma}_{y}\right),\\ \\ \boldsymbol{\beta} & \sim & \mathcal{N}\left(\boldsymbol{\mu}_{\beta},\thinspace\boldsymbol{\Sigma}_{\beta}\right), \end{array} $$ where μβ = (μ0, μ1, μ2, …, μm)T and Σβ = diag(τ02/α00, τ12/α01, τ22, …, τm2) are known and Σy = σ2In. Here, μ0 and μ1 are the prior means of the control and treatment effects, respectively, while μ2, …, μm are the prior means of the covariate effects. Likewise, τ02/α00 and τ12/α01 are the prior variances of the control and treatment effects (weighted by the discount function result α), respectively, while τ22, …, τm2 are the prior variances of the remaining covariate effects.

Using what we refer to as the Gelman parameterization (see Gelman’s Bayesian Data Analysis, 3rd edition, chapter 14, for more information), the model can be reparameterized to improve computational efficiency. First, write $$ \mathbf{y}_{\ast}=\left(\begin{array}{c} \mathbf{y}\\ \boldsymbol{\mu}_{\beta} \end{array}\right),\thinspace\mathbf{X}_{\ast}=\left(\begin{array}{c} \mathbf{X}\\ \mathbf{I}_m \end{array}\right),\thinspace\boldsymbol{\Sigma}_{\ast}=\left(\begin{array}{cc} \boldsymbol{\Sigma}_y & 0\\ 0 & \boldsymbol{\Sigma}_{\beta} \end{array}\right). $$ Then, the Gelman parameterization has the form y* = X*β + ε,   ε ∼ 𝒩(0, Σ*). The estimate of β is computed as $$ \hat{\boldsymbol{\beta}}=\mathbf{V}_{\beta}\mathbf{X}_{\ast}^T\boldsymbol{\Sigma}_{\ast}^{-1}\mathbf{y}_{\ast}, $$ where Vβ = (X*TΣ*−1X*)−1. This estimate of $\hat{\boldsymbol{\beta}}$ is the posterior mean and relies on an unknown parameter, σ2. The marginal posterior distribution of σ2 is found as $$ \begin{array}{rcl} \pi\left(\sigma^2\mid\mathbf{y}\right) & \propto & {\displaystyle \left(\frac{1}{\sigma^2}\right)^{n/2+1}\left|\mathbf{V}_{\beta}\right|^{1/2}\exp\left\{ -\frac{1}{2}\left(\mathbf{y}_{\ast}-\mathbf{X}_{\ast}\hat{\boldsymbol{\beta}}\right)^T\boldsymbol{\Sigma}_{\ast}^{-1}\left(\mathbf{y}_{\ast}-\mathbf{X}_{\ast}\hat{\boldsymbol{\beta}}\right)\right\} }. \end{array} $$ Notice that both Vβ and Σ* contain σ2. Thus, this marginal posterior of σ2 does not have a known distribution. We resort to a grid search of σ2 where 100s or 1000s of values of σ2 are proposed, on a grid, and the proposed values are sampled with probability proportional to the likelihood evaluated at the proposal.

Finally, values of σ2 sampled from the posterior distribution are then used to sample values of β from $$ \boldsymbol{\beta} \sim \mathcal{N}\left(\hat{\boldsymbol{\beta}},\, \mathbf{V}_{\beta}\right). $$

Inputting Data

The data inputs for bdplm are via dataframes data and data0 that must have matching column names. Each dataframe must have a binary column named treatment that indicates treatment vs. control. If no covariate columns are present, users should use the bdpnormal function. Currently, both data and data0 must be input since only a two-armed clinical trial with historical data has been implemented.

Examples

Two-arm trial

Throughout this package, we define a two-arm trial as an analysis where a current and/or historical control arm is present. Below we simulate a dataframe and view the estimates of the model fit.

set.seed(42)
### Simulate  data
# 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")

summary(fit)
## 
## Call:
## bdplm(formula = Y ~ treatment + x, data = df_, data0 = df0, method = "fixed")
## 
## Residuals:
##      Min     1Q Median    3Q    Max
##  -13.417 -3.018  0.276 4.227 10.088
## 
## Coefficients:
##             Estimate Std. Error
## (Intercept)   9.9342     0.4542
## treatment    31.2447     0.9273
## x             3.0147     0.1076
## 
## Discount function value (alpha):
##  treatment control
##       0.07    0.99
## 
## Residual standard error: 4.754
print(fit)
## 
## Call:
## bdplm(formula = Y ~ treatment + x, data = df_, data0 = df0, method = "fixed")
## 
## 
## Coefficients:
##  (Intercept) treatment     x
##        9.934    31.245 3.015
## 
## 
## Discount function value (alpha):
##  treatment control
##       0.07    0.99
#plot(fit)   <-- Not yet implemented