This function performs analysis of continuous data using the Time Machine approach. It takes into account all data until the investigated arm leaves the trial. It is based on linear 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_cont(
data,
arm,
alpha = 0.025,
prec_theta = 0.001,
prec_eta = 0.001,
tau_a = 0.1,
tau_b = 0.01,
prec_a = 0.001,
prec_b = 0.001,
bucket_size = 25,
check = TRUE,
...
)
Arguments
- data
Data frame with trial data, e.g. result from the
datasim_cont()
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 mean \(\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.
- prec_a
Double. Parameter \(a_{\sigma^2}\) of the Gamma distribution regarding the precision of the responses. I.e., \(1/\sigma^2 \sim Gamma(a_{\sigma^2},b_{\sigma^2})\). Default=0.001.
- prec_b
Double. Parameter \(b_{\sigma^2}\) of the Gamma distribution regarding the precision of the responses. I.e., \(1/\sigma^2 \sim Gamma(a_{\sigma^2},b_{\sigma^2})\). Default=0.001.
- 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 difference in means is less than zerotreat_effect
- posterior mean of difference in meanslower_ci
- lower limit of the (1-2*alpha
)*100% credible interval for difference in meansupper_ci
- upper limit of the (1-2*alpha
)*100% credible interval for difference in meansreject_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:
$$E(y_j) = \eta_0 + \theta_{k_j} + \alpha_{c_j}$$
where \(y_j\) is the continuous response for patient \(j\). 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. 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})$$
The precision of the individual patient responses (\(1/\sigma^2\)) is also assumed to have a Gamma hyperprior distribution:
$$1/\sigma^2 \sim Gamma(a_{\sigma^2}, b_{\sigma^2})$$
Examples
trial_data <- datasim_cont(num_arms = 3, n_arm = 100, d = c(0, 100, 250),
theta = rep(0.25, 3), lambda = rep(0.15, 4), sigma = 1, trend = "linear")
timemachine_cont(data = trial_data, arm = 3)
#> $p_val
#> [1] 0.01538333
#>
#> $treat_effect
#> [1] 0.284367
#>
#> $lower_ci
#> [1] 0.02693069
#>
#> $upper_ci
#> [1] 0.5441621
#>
#> $reject_h0
#> [1] TRUE
#>