-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bootstrap design document; method 1 for non parametric bootstrap added
- Loading branch information
1 parent
41b37f8
commit b842cf0
Showing
1 changed file
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,203 @@ | ||
--- | ||
title: "Bootstrap design" | ||
output: | ||
html_document: | ||
code_folding: hide | ||
theme: spacelab | ||
toc: true | ||
number_sections: true | ||
--- | ||
|
||
|
||
<style type="text/css"> | ||
|
||
body{ /* Normal */ | ||
font-size: 14px; | ||
} | ||
td { /* Table */ | ||
font-size: 14px; | ||
} | ||
h1.title { | ||
font-size: 28px; | ||
color: DarkRed; | ||
} | ||
h1 { /* Header 1 */ | ||
font-size: 22px; | ||
color: DarkBlue; | ||
} | ||
h2 { /* Header 2 */ | ||
font-size: 18px; | ||
color: DarkBlue; | ||
} | ||
h3 { /* Header 3 */ | ||
font-size: 18px; | ||
color: DarkBlue; | ||
} | ||
|
||
h4 { /* Header 4 */ | ||
font-size: 18px; | ||
color: DarkBlue; | ||
} | ||
|
||
code.r{ /* Code block */ | ||
font-size: 12px; | ||
} | ||
pre { /* Code block - determines code spacing between lines */ | ||
font-size: 14px; | ||
} | ||
</style> | ||
|
||
|
||
|
||
# Method 1 | ||
|
||
## Steps | ||
- Create bootstrap_HR() function to get the bootstrap weighted hazard ratios. | ||
- The bootstrap weighted hazard ratios will then be used as an input of the standard boot() function in order to obtain the | ||
bootstrap confidence interval of the weighted HR. | ||
- The boot() function will be included in the maic_tte_unanchor() function of the maic_tte_unanchored.R file so that we can get | ||
the results of all the different approaches (i.e., sandwich estimator, non-parametric bootstrap, posson approximation) for the unanchored cases | ||
of time to event endpoints. | ||
- Add additional input parameter in the maic_tte_unanchor() function to meet the requirements for the boot() function | ||
- Report bootstrap results | ||
|
||
|
||
|
||
## Bootstrapping for MAIC weighted hazard ratios | ||
|
||
The bootstrap_HR() function will be created to get the bootstrap weighted hazard ratios. | ||
This function will include the following input parameters: | ||
|
||
- *intervention_data:* A data frame containing individual patient data from the internal IPD study including | ||
columns (treatment, time, status, centered baseline characteristics) | ||
- *centered_colnames:* A character vector giving the names of the covariates to use in matching. | ||
These names must match the column names in intervention_data. | ||
- *i:* Index used to select a sample within the boot() function. | ||
- *model:* A model formula in the form 'Surv(time, status == 1) ~ treatment '. | ||
Variable names need to match the corresponding columns in intervention_data. | ||
- *comparator_data:* A data frame containing pseudo individual patient data | ||
from the comparator study needed to derive the relative treatment effect | ||
including columns (time, event, weight=1, scaled_weight=1). | ||
The outcome variables names must match intervention_data. | ||
- *min_weight:* A numeric value that defines the minimum weight allowed. | ||
This value (default 0.0001) will replace weights estimated at 0 in a sample. | ||
- *trt_ext:* A character giving the name of the comparator treatment to be used as reference | ||
|
||
|
||
Note: The bootstrap_HR() is intended to be used in conjunction with the boot() function to return the statistic | ||
to be bootstrapped. In this case by performing MAIC weighting using estimate_weights() function and returning a | ||
weighted hazard ratio (HR) from a Cox proportional hazards model. This is used as the 'statistic' argument in | ||
the boot function. | ||
|
||
From the bootstrap_HR() function we will export the HR as a numeric value. | ||
|
||
|
||
### Example code | ||
|
||
```{r}`r ''` | ||
bootstrap_HR <- function(intervention_data, centered_colnames, i, model, comparator_data, min_weight = 0.0001, trt_ext) { | ||
# create a visible binding for R CMD check | ||
wt <- NULL | ||
|
||
# Samples the data | ||
bootstrap_data <- intervention_data[i, ] | ||
|
||
# Estimates weights | ||
perform_wt <- estimate_weights(data = bootstrap_data, centered_colnames = centered_colnames) | ||
|
||
|
||
# Give comparator data weights of 1 | ||
comparator_data_wts <- comparator_data %>% dplyr::mutate(weights = 1, scaled_weights = 1) | ||
|
||
# Add the comparator data | ||
combined_data <- dplyr::bind_rows(perform_wt$data, comparator_data_wts) | ||
combined_data$treatment <- stats::relevel(as.factor(combined_data$treatment), ref = trt_ext) | ||
|
||
# set weights that are below min_weight to min_weight to avoid issues with 0 values | ||
combined_data$wt <- ifelse(combined_data$weights < min_weight, min_weight, combined_data$weights) | ||
|
||
# survival data stat | ||
cox_model <- survival::coxph(model, data = combined_data, weights = wt) | ||
HR <- exp(cox_model$coefficients) | ||
} | ||
|
||
``` | ||
## Bootstrap the confidence interval of the weighted HR | ||
The boot() function will include the following in the same format as defined in the bootstrap_HR() function: | ||
- Intervention data | ||
- The statistic to be bootsrapped; i.e. bootstap_HR | ||
- Number of bootstrap sampes | ||
- Comparator pseudo data | ||
- Matching variables | ||
- Model to fit | ||
### Example code | ||
```{r}`r ''` | ||
HR_bootstraps <- boot( | ||
data = dat_centered, # intervention data | ||
statistic = bootstrap_HR, # bootstrap the HR | ||
R = 1000, # number of bootstrap samples | ||
comparator_data = dat_ext, # comparator pseudo data | ||
centered_colnames = grep("_CENTERED$", names(dat_centered)), # matching variables | ||
model = Surv(time, status == 1) ~ treatment # model to fit | ||
) | ||
``` | ||
|
||
|
||
## Additional input parameter in the maic_tte_unanchor() function | ||
|
||
In the maic_tte_unanchor() function of the maic_tte_unanchored.R file we need to add an additional input parameter as this function will | ||
use the boot() function. Specifically, the dat_centered which is the intervention data as defined in the bootstrap_HR() function will be added. | ||
|
||
|
||
## Reporting bootstrap results | ||
|
||
Report the following: | ||
|
||
- Summarize bootstrap estimates in a histogram | ||
- Median of the bootstrap samples | ||
- Percentile CIs (This method takes the 2.5th and 97.5th percentiles) | ||
- Bias-corrected and accelerated (BCa) CI (This method attempts to correct for any bias and skewness in the distribution of bootstrap estimates) | ||
|
||
Add section 'Report 4: Bootstrapping' in the maic_tte_unanchor() function of the maic_tte_unanchored.R file | ||
|
||
|
||
### Example code | ||
|
||
```{r}`r ''` | ||
|
||
# ==> Report 4: Bootstrapping | ||
|
||
## Bootstrapping diagnostics | ||
# Summarize bootstrap estimates in a histogram | ||
# Vertical lines indicate the median and upper and lower CIs | ||
`hist(HR_bootstraps$t, main = "", xlab = "Boostrapped HR") | ||
abline(v = quantile(HR_bootstraps$t, probs = c(0.025, 0.5, 0.975)), lty = 2) | ||
|
||
# Median of the bootstrap samples | ||
HR_median <- median(HR_bootstraps$t) | ||
|
||
# Bootstrap CI - Percentile CI | ||
boot_ci_HR <- boot.ci(boot.out = HR_bootstraps, index = 1, type = "perc") | ||
|
||
# Bootstrap CI - BCa CI | ||
boot_ci_HR_BCA <- boot.ci(boot.out = HR_bootstraps, index = 1, type = "bca") | ||
|
||
res[["boot_hist"]] <- grDevices::recordPlot() | ||
res[["HR_median"]] <- HR_median | ||
res[["boot_ci_HR"]] <- boot_ci_HR | ||
res[["boot_ci_HR_BCA"]] <- boot_ci_HR_BCA` | ||
|
||
``` | ||
# Method 2 | ||
Mike to complete. |