Skip to contents

This function performs analysis of binary data using the Time Machine approach. It takes into account all data until the investigated arm leaves the trial. It is based on logistic regression with treatment as a categorical variable and covariate adjustment for time via a second-order Bayesian normal dynamic linear model (separating the trial into buckets of pre-defined size).

Usage

timemachine_bin(
  data,
  arm,
  alpha = 0.025,
  prec_theta = 0.001,
  prec_eta = 0.001,
  tau_a = 0.1,
  tau_b = 0.01,
  bucket_size = 25,
  check = TRUE,
  ...
)

Arguments

data

Data frame with trial data, e.g. result from the datasim_bin() function. Must contain columns named 'treatment', 'response' and 'period'.

arm

Integer. Index of the treatment arm under study to perform inference on (vector of length 1). This arm is compared to the control group.

alpha

Double. Decision boundary (one-sided). Default=0.025.

prec_theta

Double. Precision (\(1/\sigma^2_{\theta}\)) of the prior regarding the treatment effect \(\theta\). I.e. \(\theta \sim N(0, \sigma^2_{\theta})\) . Default=0.001.

prec_eta

Double. Precision (\(1/\sigma^2_{\eta_0}\)) of the prior regarding the control log-odds \(\eta_0\). I.e. \(\eta_0 \sim N(0, \sigma^2_{\eta_0})\). Default=0.001.

tau_a

Double. Parameter \(a_{\tau}\) of the Gamma distribution for the precision parameter \(\tau\) in the model for the time trend. I.e., \(\tau \sim Gamma(a_{\tau},b_{\tau})\). Default=0.1.

tau_b

Double. Parameter \(b_{\tau}\) of the Gamma distribution for the precision parameter \(\tau\) in the model for the time trend. I.e., \(\tau \sim Gamma(a_{\tau},b_{\tau})\). Default=0.01.

bucket_size

Integer. Number of patients per time bucket. Default=25.

check

Logical. Indicates whether the input parameters should be checked by the function. Default=TRUE, unless the function is called by a simulation function, where the default is FALSE.

...

Further arguments passed by wrapper functions when running simulations.

Value

List containing the following elements regarding the results of comparing arm to control:

  • p-val - posterior probability that the log-odds ratio is less than zero

  • treat_effect - posterior mean of log-odds ratio

  • lower_ci - lower limit of the (1-2*alpha)*100% credible interval for log-odds ratio

  • upper_ci - upper limit of the (1-2*alpha)*100% credible interval for log-odds ratio

  • reject_h0 - indicator of whether the null hypothesis was rejected or not (p_val < alpha)

Details

The Time Machine divides the trial duration into \(C\) calendar time intervals of equal length ("buckets"), which are indexed backwards in time. That is to say, the most recent time interval is denoted by \(c=1\) and the time interval corresponding to the beginning of the trial by \(c=C\). The analysis is performed as soon as the analyzed treatment arm finishes in the trial.

The model is defined as follows:

$$g(E(y_j)) = \eta_0 + \theta_{k_j} + \alpha_{c_j}$$

where \(y_j\) is the binary response for patient \(j\) and \(g(\cdot)\) is the logit link function, which maps the expected value of the patient response to the linear predictors in the model. The model intercept \(\eta_0\) denotes the response of the control group at time of the analysis, \(\theta_{k_j}\) is the effect of the treatment arm \(k\) that patient \(j\) was enrolled in, relative to control in terms of the log odds ratio. For the parameters \(\eta_0\) and \(\theta_{k_j}\), normal prior distributions are assumed, with mean 0 and variances \(\sigma^2_{\eta_0}\) and \(\sigma^2_{\theta}\), respectively:

$$\eta_0 \sim \mathcal{N}(0, \sigma^2_{\eta_0})$$

$$\theta_{k_j} \sim \mathcal{N}(0, \sigma^2_{\theta})$$

In the Time Machine, time effect is represented by \(\alpha_{c_j}\), which is the change in the response in time bucket \(c_j\) (which denotes the time bucket in which patient \(j\) is enrolled) compared to the most recent time bucket \(c=1\) and is modeled using a Bayesian second-order normal dynamic linear model. This creates a smoothing over the control response, such that closer time buckets are modeled with more similar response rates:

$$\alpha_1 = 0$$ $$\alpha_2 \sim \mathcal{N}(0, 1/\tau)$$ $$\alpha_c \sim \mathcal{N}(2 \alpha_{c-1} - \alpha_{c-2}, 1/\tau), 3 \le c \le C$$

where \(\tau\) denotes the drift parameter that controls the degree of smoothing over the time buckets and is assumed to have a Gamma hyperprior distribution:

$$\tau \sim Gamma(a_{\tau}, b_{\tau})$$

References

The Bayesian Time Machine: Accounting for Temporal Drift in Multi-arm Platform Trials. Saville, B. R., Berry, D. A., et al. Clinical Trials 19.5 (2022): 490-501.

Author

Dominic Magirr, Peter Jacko

Examples


trial_data <- datasim_bin(num_arms = 3, n_arm = 100, d = c(0, 100, 250),
p0 = 0.7, OR = rep(1.8, 3), lambda = rep(0.15, 4), trend="stepwise")

timemachine_bin(data = trial_data, arm = 3)
#> $p_val
#> [1] 0.07158333
#> 
#> $treat_effect
#> [1] 0.5065646
#> 
#> $lower_ci
#> [1] -0.1672956
#> 
#> $upper_ci
#> [1] 1.175277
#> 
#> $reject_h0
#> [1] FALSE
#>