Skip to contents

Fit a Stan MAP prior generation model to summary-level data.

Usage

stan_map_summary_data(y, n, time, a_alpha, a_beta, b_alpha, b_beta, ...)

Arguments

y

integer vector, number of events in the trials.

n

integer vector, number of patients in the trials.

time,

numeric vector, strictly positive, time at risk in the trials.

a_alpha

numeric, first shape param of beta prior on a. See Details.

a_beta

numeric, second shape param of beta prior on a. See Details.

b_alpha

numeric, first shape param of beta prior on b. See Details.

b_beta

numeric, second shape param of beta prior on b. See Details.

...

extra parameters are passed to sampling.

Value

object of type bssd_binary_map.

Details

This routine fits the meta-analytical model equation: $$ log(-log(1 - p_{i})) = \alpha_{i} + log(T_{i}) $$ where \(p_{i}\) is the probability of event in trial i, adjusted for the intended or average time-at-risk, \(T_{i}\). The model is equivalent to: $$ log(\lambda_{i}) = \alpha_{i} $$ where $$ \lambda_{i} = -log(1 - p_{i}) / T_{i} $$ is the hazard of the event, assumed constant through time, and \(p_{i}\) is the probability of event in unit time in trial i. Thus this is a random-effects model that assumes the log-hazard terms are exchangeable across trials, and the \( \alpha_{i} \) terms are trial-specific intercepts. To complete the meta-analytical model, we apply the hierarchical distribution $$ p_{j} \sim Beta(abN, (1-a)bN) $$ where N is the total number of patients in the historical trials, and a and b are hyperparameters. To illustrate the role of a and b, consider that the effective sample size of this distribution is \(abN + (1-a)bN) = bN\), i.e. b is a discount to the historical data, taking values on (0, 1). Furthermore, the mean of this distribution is \( abN / bN = a\). Thus, a is the expected probability of event in unit time, and once again a is bound to the range (0, 1). Hyperpriors \( a \sim Beta(a_{\alpha}, a_{\beta}) \) and \( b \sim Beta(b_{\alpha}, b_{\beta}) \) are natural choices to enforce these ranges. This method creates a prior from summary-level data, requiring only the intended or average times-at-risk and total counts of patients with an adverse event in each trial. It is likely aggregate statistics like this can be derived from publications and/or filings. However, if you have patient-level times-at-risk and adverse event statuses, stan_map_patient_data provides a similar method to create a prior from patient-level data. The patient-level approach is generally preferable because it allows adjustment for how long each individual patient spent at risk.

This model is effectively the same as that fit by stan_map_patient_data with the notable exception that since patient-level times-at-risk are not known, the intended trial follow-up times, \( T_{j} \), are used instead.

Note: setting a seed in R does not affect the state of the random generator in stan. If a reproducible output is desired, then the optional parameter seed needs to be populated. For additional information about this parameter, see sampling.

Examples

set.seed(2021)
H <- 10
time <- 0.5 + cumsum(rexp(H, 5))
# Use constant hazard model:
hazard <- 0.15
prob <- 1 - exp(- hazard * time)
n <- rpois(H, lambda = 100 * time)
y <- rbinom(H, size = n, prob = prob)
x <- stan_map_summary_data(y = y, n = n, time = time,
                           a_alpha = 1 / 3, a_beta = 1 / 3,
                           b_alpha = 5, b_beta = 5)
#> 
#> SAMPLING FOR MODEL 'map_prior_summary_data' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 1.8e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.18 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1: 
#> Chain 1: 
#> Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 0.074 seconds (Warm-up)
#> Chain 1:                0.079 seconds (Sampling)
#> Chain 1:                0.153 seconds (Total)
#> Chain 1: 
#> 
#> SAMPLING FOR MODEL 'map_prior_summary_data' NOW (CHAIN 2).
#> Chain 2: 
#> Chain 2: Gradient evaluation took 1e-05 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.1 seconds.
#> Chain 2: Adjust your expectations accordingly!
#> Chain 2: 
#> Chain 2: 
#> Chain 2: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 2: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 2: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 2: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 2: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 2: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 2: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 2: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 2: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 2: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 2: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 2: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 2: 
#> Chain 2:  Elapsed Time: 0.069 seconds (Warm-up)
#> Chain 2:                0.081 seconds (Sampling)
#> Chain 2:                0.15 seconds (Total)
#> Chain 2: 
#> 
#> SAMPLING FOR MODEL 'map_prior_summary_data' NOW (CHAIN 3).
#> Chain 3: 
#> Chain 3: Gradient evaluation took 1e-05 seconds
#> Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.1 seconds.
#> Chain 3: Adjust your expectations accordingly!
#> Chain 3: 
#> Chain 3: 
#> Chain 3: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 3: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 3: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 3: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 3: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 3: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 3: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 3: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 3: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 3: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 3: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 3: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 3: 
#> Chain 3:  Elapsed Time: 0.072 seconds (Warm-up)
#> Chain 3:                0.076 seconds (Sampling)
#> Chain 3:                0.148 seconds (Total)
#> Chain 3: 
#> 
#> SAMPLING FOR MODEL 'map_prior_summary_data' NOW (CHAIN 4).
#> Chain 4: 
#> Chain 4: Gradient evaluation took 1e-05 seconds
#> Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.1 seconds.
#> Chain 4: Adjust your expectations accordingly!
#> Chain 4: 
#> Chain 4: 
#> Chain 4: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 4: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 4: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 4: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 4: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 4: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 4: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 4: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 4: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 4: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 4: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 4: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 4: 
#> Chain 4:  Elapsed Time: 0.068 seconds (Warm-up)
#> Chain 4:                0.06 seconds (Sampling)
#> Chain 4:                0.128 seconds (Total)
#> Chain 4: 
x
#> Prob(Event): Mean 0.148 (95% HPDI 0.129, 0.168)
#> MAP Prob(Event): Mean 0.148 (95% HPDI 0.113, 0.183)