TLG Catalog - Stable
  • Stable
    • Dev
  1. Tables
  2. Efficacy
  3. RBMIT01
  • Introduction

  • Tables
    • ADA
      • ADAT01
      • ADAT02
      • ADAT03
      • ADAT04A
      • ADAT04B
    • Adverse Events
      • AET01
      • AET01_AESI
      • AET02
      • AET02_SMQ
      • AET03
      • AET04
      • AET04_PI
      • AET05
      • AET05_ALL
      • AET06
      • AET06_SMQ
      • AET07
      • AET09
      • AET09_SMQ
      • AET10
    • Concomitant Medications
      • CMT01
      • CMT01A
      • CMT01B
      • CMT02_PT
    • Deaths
      • DTHT01
    • Demography
      • DMT01
    • Disclosures
      • DISCLOSUREST01
      • EUDRAT01
      • EUDRAT02
    • Disposition
      • DST01
      • PDT01
      • PDT02
    • ECG
      • EGT01
      • EGT02
      • EGT03
      • EGT04
      • EGT05_QTCAT
    • Efficacy
      • AOVT01
      • AOVT02
      • AOVT03
      • CFBT01
      • CMHT01
      • COXT01
      • COXT02
      • DORT01
      • LGRT02
      • MMRMT01
      • ONCT05
      • RATET01
      • RBMIT01
      • RSPT01
      • TTET01
    • Exposure
      • EXT01
    • Lab Results
      • LBT01
      • LBT02
      • LBT03
      • LBT04
      • LBT05
      • LBT06
      • LBT07
      • LBT08
      • LBT09
      • LBT10
      • LBT10_BL
      • LBT11
      • LBT11_BL
      • LBT12
      • LBT12_BL
      • LBT13
      • LBT14
      • LBT15
    • Medical History
      • MHT01
    • Pharmacokinetic
      • PKCT01
      • PKPT02
      • PKPT03
      • PKPT04
      • PKPT05
      • PKPT06
      • PKPT07
      • PKPT08
      • PKPT11
    • Risk Management Plan
      • RMPT01
      • RMPT03
      • RMPT04
      • RMPT05
      • RMPT06
    • Safety
      • ENTXX
    • Vital Signs
      • VST01
      • VST02
  • Listings
    • ADA
      • ADAL02
    • Adverse Events
      • AEL01
      • AEL01_NOLLT
      • AEL02
      • AEL02_ED
      • AEL03
      • AEL04
    • Concomitant Medications
      • CML01
      • CML02A_GL
      • CML02B_GL
    • Development Safety Update Report
      • DSUR4
    • Disposition
      • DSL01
      • DSL02
    • ECG
      • EGL01
    • Efficacy
      • ONCL01
    • Exposure
      • EXL01
    • Lab Results
      • LBL01
      • LBL01_RLS
      • LBL02A
      • LBL02A_RLS
      • LBL02B
    • Medical History
      • MHL01
    • Pharmacokinetic
      • ADAL01
      • PKCL01
      • PKCL02
      • PKPL01
      • PKPL02
      • PKPL04
    • Vital Signs
      • VSL01
  • Graphs
    • Efficacy
      • FSTG01
      • FSTG02
      • KMG01
      • MMRMG01
      • MMRMG02
    • Other
      • BRG01
      • BWG01
      • CIG01
      • IPPG01
      • LTG01
      • MNG01
    • Pharmacokinetic
      • PKCG01
      • PKCG02
      • PKCG03
      • PKPG01
      • PKPG02
      • PKPG03
      • PKPG04
      • PKPG06

  • Appendix
    • Reproducibility

  • Index

On this page

  • Reproducibility
    • Timestamp
    • Session Info
    • .lock file
  • Edit this page
  • Report an issue
  1. Tables
  2. Efficacy
  3. RBMIT01

RBMIT01

Tables for RBMI


  • Creating Intercurrent Event Data
  • Define Key Variables

Set the imputation strategy to "MAR" for each patient with at least one missing observation.

Code
data_ice <- data_full %>%
  dplyr::arrange(dplyr::across(.cols = c("TMP_ID", vars$visit))) %>%
  dplyr::filter(is.na(.data[[missing_var]])) %>%
  dplyr::group_by(TMP_ID) %>%
  dplyr::slice(1) %>%
  dplyr::ungroup() %>%
  dplyr::select(all_of(c("TMP_ID", vars$visit))) %>%
  dplyr::mutate(strategy = "MAR")

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.

Code
debug_mode <- FALSE

draws_vars <- rbmi::set_vars(
  outcome = missing_var,
  visit = vars$visit,
  group = vars$group,
  covariates = covariates$draws
)
draws_vars$subjid <- "TMP_ID"

Define which imputation method to use, then create samples for the imputation parameters by running the draws() function.

Code
set.seed(123)
draws_method <- method_bayes()

draws_obj <- rbmi::draws(
  data = data_full,
  data_ice = data_ice,
  vars = draws_vars,
  method = draws_method
)

SAMPLING FOR MODEL 'rbmi_mmrm' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.000253 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 2.53 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.516 seconds (Warm-up)
Chain 1:                1.723 seconds (Sampling)
Chain 1:                2.239 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:

Code
impute_references <- c("DRUG" = "PLACEBO", "PLACEBO" = "PLACEBO")

impute_obj <- rbmi::impute(
  draws_obj,
  references = impute_references
)

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
library(broom)

pool_obj <- rbmi::pool(
  results = analyse_obj,
  conf.level = 0.95,
  alternative = c("two.sided", "less", "greater"),
  type = c("percentile", "normal")
)

df <- tidy(pool_obj)
df
  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.211387 0.6525571    -5.500112   -2.9226622          NA        NA
4   alt -2.816515 0.6425104    -4.085651   -1.5473781  1.39487231 0.9218396
5   ref -6.330807 0.7380612    -7.792088   -4.8695255          NA        NA
6   alt -4.141827 0.7031348    -5.532346   -2.7513085  2.18897960 1.0486129
7   ref -7.606561 0.7841521    -9.157770   -6.0553518          NA        NA
8   alt -4.766613 0.7756463    -6.301895   -3.2313311  2.83994789 1.1247163
  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.4259331       3.215678 0.13225425    -0.33121447     5       0.95
5             NA             NA         NA             NA     6       0.95
6      0.1115328       4.266426 0.03908636    -0.34576630     6       0.95
7             NA             NA         NA             NA     7       0.95
8      0.6127363       5.067159 0.01289367    -0.37335505     7       0.95

Create Output

Finally, use functions from the rtables and tern packages to generate a nicely formatted rtable object.

Code
result <- basic_table() %>%
  split_cols_by("group", ref_group = levels(df$group)[1]) %>%
  split_rows_by("visit", split_label = "Visit", label_pos = "topleft") %>%
  summarize_rbmi() %>%
  build_table(df)
result
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.211 (0.653)     -2.817 (0.643) 
    95% CI                            (-5.500, -2.923)   (-4.086, -1.547)
  Difference in Adjusted Means (SE)                       1.395 (0.922)  
    95% CI                                               (-0.426, 3.216) 
    Relative Reduction (%)                                    -33.1%     
    p-value (RBMI)                                            0.1323     
6                                                                        
  Adjusted Mean (SE)                   -6.331 (0.738)     -4.142 (0.703) 
    95% CI                            (-7.792, -4.870)   (-5.532, -2.751)
  Difference in Adjusted Means (SE)                       2.189 (1.049)  
    95% CI                                                (0.112, 4.266) 
    Relative Reduction (%)                                    -34.6%     
    p-value (RBMI)                                            0.0391     
7                                                                        
  Adjusted Mean (SE)                   -7.607 (0.784)     -4.767 (0.776) 
    95% CI                            (-9.158, -6.055)   (-6.302, -3.231)
  Difference in Adjusted Means (SE)                       2.840 (1.125)  
    95% CI                                                (0.613, 5.067) 
    Relative Reduction (%)                                    -37.3%     
    p-value (RBMI)                                            0.0129     

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] "2025-07-05 17:40:31 UTC"

Session Info

─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.0 (2025-04-11)
 os       Ubuntu 24.04.2 LTS
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Etc/UTC
 date     2025-07-05
 pandoc   3.7.0.2 @ /usr/bin/ (via rmarkdown)
 quarto   1.7.32 @ /usr/local/bin/quarto

─ 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.8   2025-03-28 [1] RSPM
 callr          3.7.6   2024-03-25 [1] RSPM
 checkmate      2.3.2   2024-07-29 [1] RSPM
 cli            3.6.5   2025-04-23 [1] RSPM
 codetools      0.2-20  2024-03-31 [2] CRAN (R 4.5.0)
 curl           6.4.0   2025-06-22 [1] RSPM
 dichromat      2.0-0.1 2022-05-02 [1] CRAN (R 4.5.0)
 digest         0.6.37  2024-08-19 [1] RSPM
 dplyr        * 1.1.4   2023-11-17 [1] RSPM
 evaluate       1.0.4   2025-06-18 [1] RSPM
 farver         2.1.2   2024-05-13 [1] RSPM
 fastmap        1.2.0   2024-05-15 [1] RSPM
 formatters   * 0.5.11  2025-04-09 [1] RSPM
 generics       0.1.4   2025-05-09 [1] RSPM
 ggplot2        3.5.2   2025-04-09 [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.21  2025-01-09 [1] CRAN (R 4.5.0)
 jsonlite       2.0.0   2025-03-27 [1] RSPM
 knitr          1.50    2025-03-16 [1] RSPM
 lattice        0.22-7  2025-04-02 [2] CRAN (R 4.5.0)
 lifecycle      1.0.4   2023-11-07 [1] RSPM
 loo            2.8.0   2024-07-03 [1] CRAN (R 4.5.0)
 magrittr     * 2.0.3   2022-03-30 [1] RSPM
 Matrix         1.7-3   2025-03-11 [1] CRAN (R 4.5.0)
 matrixStats    1.5.0   2025-01-07 [1] CRAN (R 4.5.0)
 mmrm           0.3.15  2025-06-10 [1] RSPM
 nestcolor      0.1.3   2025-01-21 [1] RSPM
 nlme           3.1-168 2025-03-31 [2] CRAN (R 4.5.0)
 pillar         1.11.0  2025-07-04 [1] RSPM
 pkgbuild       1.4.8   2025-05-26 [1] RSPM
 pkgcache       2.2.4   2025-05-26 [1] RSPM
 pkgconfig      2.0.3   2019-09-22 [1] RSPM
 processx       3.8.6   2025-02-21 [1] RSPM
 ps             1.9.1   2025-04-12 [1] RSPM
 purrr          1.0.4   2025-02-05 [1] RSPM
 QuickJSR       1.8.0   2025-06-09 [1] CRAN (R 4.5.0)
 R6             2.6.1   2025-02-15 [1] RSPM
 rbibutils      2.3     2024-10-04 [1] RSPM
 rbmi         * 1.4.1   2025-03-03 [1] RSPM
 RColorBrewer   1.1-3   2022-04-03 [1] RSPM
 Rcpp           1.1.0   2025-07-02 [1] RSPM
 RcppParallel   5.1.10  2025-01-24 [1] CRAN (R 4.5.0)
 Rdpack         2.6.4   2025-04-09 [1] RSPM
 rlang          1.1.6   2025-04-11 [1] RSPM
 rmarkdown      2.29    2024-11-04 [1] RSPM
 rstan          2.32.7  2025-03-10 [1] CRAN (R 4.5.0)
 rtables      * 0.6.13  2025-06-19 [1] RSPM
 scales         1.4.0   2025-04-24 [1] RSPM
 sessioninfo    1.2.3   2025-02-05 [1] any (@1.2.3)
 StanHeaders    2.32.10 2024-07-15 [1] CRAN (R 4.5.0)
 stringi        1.8.7   2025-03-27 [1] RSPM
 stringr        1.5.1   2023-11-14 [1] RSPM
 survival       3.8-3   2024-12-17 [2] CRAN (R 4.5.0)
 tern         * 0.9.9   2025-06-20 [1] RSPM
 tern.rbmi    * 0.1.5   2025-07-05 [1] https://i~
 testthat       3.2.3   2025-01-13 [1] RSPM
 tibble         3.3.0   2025-06-08 [1] RSPM
 tidyr          1.3.1   2024-01-24 [1] RSPM
 tidyselect     1.2.1   2024-03-11 [1] RSPM
 TMB            1.9.17  2025-03-10 [1] RSPM
 V8             6.0.4   2025-06-04 [1] CRAN (R 4.5.0)
 vctrs          0.6.5   2023-12-01 [1] RSPM
 withr          3.0.2   2024-10-28 [1] RSPM
 xfun           0.52    2025-04-02 [1] RSPM
 yaml           2.3.10  2024-07-26 [1] RSPM

 [1] /usr/local/lib/R/site-library
 [2] /usr/local/lib/R/library
 [3] /github/home/R/x86_64-pc-linux-gnu-library/4.5
 * ── Packages attached to the search path.

──────────────────────────────────────────────────────────────────────────────

.lock file

Download the .lock file and use renv::restore() on it to recreate environment used to generate this website.

Download

RATET01
RSPT01
Source Code
---
title: RBMIT01
subtitle: Tables for RBMI
---

------------------------------------------------------------------------

{{< include ../../_utils/envir_hook.qmd >}}

```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
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))
```

::: panel-tabset
#### Creating Intercurrent Event Data

Set the imputation strategy to `"MAR"` for each patient with at least one missing observation.

```{r}
#| code-fold: show

data_ice <- data_full %>%
  dplyr::arrange(dplyr::across(.cols = c("TMP_ID", vars$visit))) %>%
  dplyr::filter(is.na(.data[[missing_var]])) %>%
  dplyr::group_by(TMP_ID) %>%
  dplyr::slice(1) %>%
  dplyr::ungroup() %>%
  dplyr::select(all_of(c("TMP_ID", vars$visit))) %>%
  dplyr::mutate(strategy = "MAR")
```

## 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 Key Variables

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.

```{r}
#| code-fold: show

debug_mode <- FALSE

draws_vars <- rbmi::set_vars(
  outcome = missing_var,
  visit = vars$visit,
  group = vars$group,
  covariates = covariates$draws
)
draws_vars$subjid <- "TMP_ID"
```

Define which imputation method to use, then create samples for the imputation parameters by running the `draws()` function.


```{r, warning = FALSE}
#| code-fold: show

set.seed(123)
draws_method <- method_bayes()

draws_obj <- rbmi::draws(
  data = data_full,
  data_ice = data_ice,
  vars = draws_vars,
  method = draws_method
)
```

## 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:

```{r}
#| code-fold: show

impute_references <- c("DRUG" = "PLACEBO", "PLACEBO" = "PLACEBO")

impute_obj <- rbmi::impute(
  draws_obj,
  references = impute_references
)
```

## 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.

```{r}
#| code-fold: show

# 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.

```{r}
#| code-fold: show

library(broom)

pool_obj <- rbmi::pool(
  results = analyse_obj,
  conf.level = 0.95,
  alternative = c("two.sided", "less", "greater"),
  type = c("percentile", "normal")
)

df <- tidy(pool_obj)
df
```

## Create Output

Finally, use functions from the `rtables` and `tern` packages to generate a nicely formatted `rtable` object.

```{r variant1, test = list(result_v1 = "result")}
result <- basic_table() %>%
  split_cols_by("group", ref_group = levels(df$group)[1]) %>%
  split_rows_by("visit", split_label = "Visit", label_pos = "topleft") %>%
  summarize_rbmi() %>%
  build_table(df)
result
```

## 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.

```{r setup}
#| code-fold: show
```
:::

{{< include ../../_utils/save_results.qmd >}}

{{< include ../../repro.qmd >}}

Made with ❤️ by the NEST Team

  • Edit this page
  • Report an issue
Cookie Preferences