RBMIT01
Tables for RBMI
Set the imputation strategy to "MAR"
for each patient with at least one missing observation.
Draws
The rbmi::draws()
function fits the imputation models and stores the corresponding parameter estimates or Bayesian posterior parameter draws. The three main inputs to the rbmi::draws()
function are:
-
data
- The primary longitudinal data.frame containing the outcome variable and all covariates. -
data_ice
- A data.frame which specifies the first visit affected by an intercurrent event (ICE) and the imputation strategy for handling missing outcome data after the ICE. At most one ICE which is to be imputed by a non-MAR strategy is allowed per subject. -
method
- The statistical method used to fit the imputation models and to create imputed datasets.
Define the names of key variables in our dataset and the covariates included in the imputation model using rbmi::set_vars()
. Note that the covariates
argument can also include interaction terms.
Define which imputation method to use, then create samples for the imputation parameters by running the draws()
function.
Code
Compiling Stan model please wait...
SAMPLING FOR MODEL 'rbmi_mmrm' NOW (CHAIN 1).
Chain 1:
Chain 1: Gradient evaluation took 0.000251 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 2.51 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1:
Chain 1:
Chain 1: Iteration: 1 / 1200 [ 0%] (Warmup)
Chain 1: Iteration: 120 / 1200 [ 10%] (Warmup)
Chain 1: Iteration: 201 / 1200 [ 16%] (Sampling)
Chain 1: Iteration: 320 / 1200 [ 26%] (Sampling)
Chain 1: Iteration: 440 / 1200 [ 36%] (Sampling)
Chain 1: Iteration: 560 / 1200 [ 46%] (Sampling)
Chain 1: Iteration: 680 / 1200 [ 56%] (Sampling)
Chain 1: Iteration: 800 / 1200 [ 66%] (Sampling)
Chain 1: Iteration: 920 / 1200 [ 76%] (Sampling)
Chain 1: Iteration: 1040 / 1200 [ 86%] (Sampling)
Chain 1: Iteration: 1160 / 1200 [ 96%] (Sampling)
Chain 1: Iteration: 1200 / 1200 [100%] (Sampling)
Chain 1:
Chain 1: Elapsed Time: 0.503 seconds (Warm-up)
Chain 1: 1.645 seconds (Sampling)
Chain 1: 2.148 seconds (Total)
Chain 1:
Impute
The next step is to use the parameters from the imputation model to generate the imputed datasets. This is done via the rbmi::impute()
function. The function only has two key inputs: the imputation model output from rbmi::draws()
and the reference groups relevant to reference-based imputation methods. It’s usage is thus:
Analyze
The next step is to run the analysis model on each imputed dataset. This is done by defining an analysis function and then calling rbmi::analyse()
to apply this function to each imputed dataset.
Code
# Define analysis model
analyse_fun <- ancova
ref_levels <- levels(impute_obj$data$group[[1]])
names(ref_levels) <- c("ref", "alt")
analyse_obj <- rbmi::analyse(
imputations = impute_obj,
fun = analyse_fun,
vars = rbmi::set_vars(
subjid = "TMP_ID",
outcome = missing_var,
visit = vars$visit,
group = vars$group,
covariates = covariates$analyse
)
)
Pool
The rbmi::pool()
function can be used to summarize the analysis results across multiple imputed datasets to provide an overall statistic with a standard error, confidence intervals and a p-value for the hypothesis test of the null hypothesis that the effect is equal to 0. Using the broom::tidy()
function the rbmi
final results are reshaped.
Code
group est se_est lower_cl_est upper_cl_est est_contr se_contr
1 ref -1.615820 0.4862316 -2.575771 -0.6558685 NA NA
2 alt -1.707626 0.4749573 -2.645319 -0.7699335 -0.09180645 0.6826279
3 ref -4.218952 0.6505048 -5.503615 -2.9342892 NA NA
4 alt -2.815275 0.6364376 -4.072204 -1.5583461 1.40367691 0.9149382
5 ref -6.330717 0.7020406 -7.717703 -4.9437297 NA NA
6 alt -4.177543 0.6863985 -5.533665 -2.8214218 2.15317319 0.9854002
7 ref -7.540923 0.8133804 -9.152471 -5.9293739 NA NA
8 alt -4.824323 0.7521449 -6.310829 -3.3378160 2.71660019 1.1225222
lower_cl_contr upper_cl_contr p_value relative_reduc visit conf_level
1 NA NA NA NA 4 0.95
2 -1.4394968 1.255884 0.89317724 0.05681725 4 0.95
3 NA NA NA NA 5 0.95
4 -0.4032862 3.210640 0.12696838 -0.33270747 5 0.95
5 NA NA NA NA 6 0.95
6 0.2063790 4.099967 0.03040925 -0.34011524 6 0.95
7 NA NA NA NA 7 0.95
8 0.4945431 4.938657 0.01698541 -0.36024772 7 0.95
Create Output
Finally, use functions from the rtables
and tern
packages to generate a nicely formatted rtable
object.
Code
Visit ref alt
—————————————————————————————————————————————————————————————————————————
4
Adjusted Mean (SE) -1.616 (0.486) -1.708 (0.475)
95% CI (-2.576, -0.656) (-2.645, -0.770)
Difference in Adjusted Means (SE) -0.092 (0.683)
95% CI (-1.439, 1.256)
Relative Reduction (%) 5.7%
p-value (RBMI) 0.8932
5
Adjusted Mean (SE) -4.219 (0.651) -2.815 (0.636)
95% CI (-5.504, -2.934) (-4.072, -1.558)
Difference in Adjusted Means (SE) 1.404 (0.915)
95% CI (-0.403, 3.211)
Relative Reduction (%) -33.3%
p-value (RBMI) 0.1270
6
Adjusted Mean (SE) -6.331 (0.702) -4.178 (0.686)
95% CI (-7.718, -4.944) (-5.534, -2.821)
Difference in Adjusted Means (SE) 2.153 (0.985)
95% CI (0.206, 4.100)
Relative Reduction (%) -34.0%
p-value (RBMI) 0.0304
7
Adjusted Mean (SE) -7.541 (0.813) -4.824 (0.752)
95% CI (-9.152, -5.929) (-6.311, -3.338)
Difference in Adjusted Means (SE) 2.717 (1.123)
95% CI (0.495, 4.939)
Relative Reduction (%) -36.0%
p-value (RBMI) 0.0170
Data Setup
We use a publicly available example dataset from an antidepressant clinical trial of an active drug versus placebo from the rbmi
package. The relevant endpoint is the Hamilton 17-item depression rating scale (HAMD17
) which was assessed at baseline and at weeks 1, 2, 4, and 6. Study drug discontinuation occurred in 24% of subjects from the active drug and 26% of subjects from placebo. All data after study drug discontinuation are missing and there is a single additional intermittent missing observation.
Code
library(tern.rbmi)
library(dplyr)
set.seed(123)
data <- antidepressant_data
levels(data$THERAPY) <- c("PLACEBO", "DRUG") # This is important! The order defines the computation order later
missing_var <- "CHANGE"
vars <- list(
id = "PATIENT",
visit = "VISIT",
expand_vars = c("BASVAL", "THERAPY"),
group = "THERAPY"
)
covariates <- list(
draws = c("BASVAL*VISIT", "THERAPY*VISIT"),
analyse = c("BASVAL")
)
data <- data %>%
dplyr::select(PATIENT, THERAPY, VISIT, BASVAL, THERAPY, CHANGE) %>%
dplyr::mutate(dplyr::across(.cols = vars$id, ~ as.factor(.x))) %>%
dplyr::arrange(dplyr::across(.cols = c(vars$id, vars$visit)))
# Use expand_locf to add rows corresponding to visits with missing outcomes to the dataset
data_full <- do.call(
expand_locf,
args = list(
data = data,
vars = c(vars$expand_vars, vars$group),
group = vars$id,
order = c(vars$id, vars$visit)
) %>%
append(lapply(data[c(vars$id, vars$visit)], levels))
)
data_full <- data_full %>%
dplyr::group_by(dplyr::across(vars$id)) %>%
dplyr::mutate(!!vars$group := Filter(Negate(is.na), .data[[vars$group]])[1])
# there are duplicates - use first value
data_full <- data_full %>%
dplyr::group_by(dplyr::across(c(vars$id, vars$group, vars$visit))) %>%
dplyr::slice(1) %>%
dplyr::ungroup()
# need to have a single ID column
data_full <- data_full %>%
tidyr::unite("TMP_ID", dplyr::all_of(vars$id), sep = "_#_", remove = FALSE) %>%
dplyr::mutate(TMP_ID = as.factor(TMP_ID))
Reproducibility
Timestamp
[1] "2024-11-26 06:12:54 UTC"
Session Info
─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 4.4.1 (2024-06-14)
os Ubuntu 22.04.5 LTS
system x86_64, linux-gnu
ui X11
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Etc/UTC
date 2024-11-26
pandoc 3.4 @ /usr/bin/ (via rmarkdown)
─ Packages ───────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
assertthat 0.2.1 2019-03-21 [1] RSPM
backports 1.5.0 2024-05-23 [1] RSPM
brio 1.1.5 2024-04-24 [1] RSPM
broom * 1.0.7 2024-09-26 [1] RSPM
callr 3.7.6 2024-03-25 [1] RSPM
checkmate 2.3.2 2024-07-29 [1] RSPM
cli 3.6.3 2024-06-21 [1] RSPM
codetools 0.2-20 2024-03-31 [2] CRAN (R 4.4.1)
colorspace 2.1-1 2024-07-26 [1] RSPM
curl 6.0.1 2024-11-14 [1] RSPM
digest 0.6.37 2024-08-19 [1] RSPM
dplyr * 1.1.4 2023-11-17 [1] RSPM
evaluate 1.0.1 2024-10-10 [1] RSPM
fansi 1.0.6 2023-12-08 [1] RSPM
fastmap 1.2.0 2024-05-15 [1] RSPM
formatters * 0.5.9.9005 2024-11-26 [1] https://p~
generics 0.1.3 2022-07-05 [1] RSPM
ggplot2 3.5.1 2024-04-23 [1] RSPM
glue 1.8.0 2024-09-30 [1] RSPM
gridExtra 2.3 2017-09-09 [1] RSPM
gtable 0.3.6 2024-10-25 [1] RSPM
htmltools 0.5.8.1 2024-04-04 [1] RSPM
htmlwidgets 1.6.4 2023-12-06 [1] RSPM
inline 0.3.19 2021-05-31 [1] CRAN (R 4.4.1)
jsonlite 1.8.9 2024-09-20 [1] RSPM
knitr 1.49 2024-11-08 [1] RSPM
lattice 0.22-6 2024-03-20 [2] CRAN (R 4.4.1)
lifecycle 1.0.4 2023-11-07 [1] RSPM
loo 2.8.0 2024-07-03 [1] CRAN (R 4.4.1)
magrittr * 2.0.3 2022-03-30 [1] RSPM
Matrix 1.7-1 2024-10-18 [1] RSPM
matrixStats 1.4.1 2024-09-08 [1] CRAN (R 4.4.1)
mmrm 0.3.14.9001 2024-11-26 [1] https://p~
munsell 0.5.1 2024-04-01 [1] RSPM
nestcolor 0.1.2.9017 2024-11-26 [1] https://p~
nlme 3.1-166 2024-08-14 [2] CRAN (R 4.4.1)
pillar 1.9.0 2023-03-22 [1] RSPM
pkgbuild 1.4.5 2024-10-28 [1] RSPM
pkgcache 2.2.3 2024-09-12 [1] RSPM
pkgconfig 2.0.3 2019-09-22 [1] RSPM
processx 3.8.4 2024-03-16 [1] RSPM
ps 1.8.1 2024-10-28 [1] RSPM
purrr 1.0.2 2023-08-10 [1] RSPM
QuickJSR 1.4.0 2024-10-01 [1] CRAN (R 4.4.1)
R6 2.5.1 2021-08-19 [1] RSPM
rbibutils 2.3 2024-10-04 [1] RSPM
rbmi * 1.3.0.9000 2024-11-26 [1] https://p~
Rcpp 1.0.13-1 2024-11-02 [1] RSPM
RcppParallel 5.1.9 2024-08-19 [1] CRAN (R 4.4.1)
Rdpack 2.6.2 2024-11-15 [1] RSPM
rlang 1.1.4 2024-06-04 [1] RSPM
rmarkdown 2.29 2024-11-04 [1] RSPM
rstan 2.32.6 2024-03-05 [1] CRAN (R 4.4.1)
rtables * 0.6.10.9005 2024-11-26 [1] https://p~
scales 1.3.0 2023-11-28 [1] RSPM
sessioninfo 1.2.2 2021-12-06 [1] any (@1.2.2)
StanHeaders 2.32.10 2024-07-15 [1] CRAN (R 4.4.1)
stringi 1.8.4 2024-05-06 [1] RSPM
stringr 1.5.1 2023-11-14 [1] RSPM
survival 3.7-0 2024-06-05 [2] CRAN (R 4.4.1)
svglite 2.1.3 2023-12-08 [1] RSPM
systemfonts 1.1.0 2024-05-15 [1] RSPM
tern * 0.9.6.9016 2024-11-26 [1] https://p~
tern.rbmi * 0.1.3.9012 2024-11-26 [1] https://p~
testthat 3.2.1.1 2024-04-14 [1] RSPM
tibble 3.2.1 2023-03-20 [1] RSPM
tidyr 1.3.1 2024-01-24 [1] RSPM
tidyselect 1.2.1 2024-03-11 [1] RSPM
TMB 1.9.15 2024-09-09 [1] RSPM
utf8 1.2.4 2023-10-22 [1] RSPM
V8 6.0.0 2024-10-12 [1] CRAN (R 4.4.1)
vctrs 0.6.5 2023-12-01 [1] RSPM
withr 3.0.2 2024-10-28 [1] RSPM
xfun 0.49 2024-10-31 [1] RSPM
yaml 2.3.10 2024-07-26 [1] RSPM
[1] /usr/local/lib/R/site-library
[2] /usr/local/lib/R/library
──────────────────────────────────────────────────────────────────────────────
.lock
file
Download the .lock
file and use renv::restore()
on it to recreate environment used to generate this website.