Learn R Programming

rbmiUtils

rbmiUtils extends the functionality of rbmi to support more streamlined workflows for multiple imputation in clinical trials. It is designed to simplify key tasks such as analysis execution, pooling, result tidying, and imputed data handling.

Table of Contents

Installation

You can install the package from cran or the development version of rbmiUtils from GitHub:

TypeSourceCommand
ReleaseCRANinstall.packages("rbmiUtils")
DevelopmentGitHubremotes::install_github("openpharma/rbmiUtils")

Example

This example shows how to run a covariate-adjusted ANCOVA on imputed datasets using Bayesian multiple imputation:

library(dplyr)
library(rbmi)
library(rbmiUtils)

data("ADMI")

# Setup
N_IMPUTATIONS <- 100
WARMUP <- 200
THIN <- 5

# Preprocessing
ADMI <- ADMI %>%
  mutate(
    TRT = factor(TRT, levels = c("Placebo", "Drug A")),
    USUBJID = factor(USUBJID),
    AVISIT = factor(AVISIT)
  )

# Define analysis variables
vars <- set_vars(
  subjid = "USUBJID",
  visit = "AVISIT",
  group = "TRT",
  outcome = "CHG",
  covariates = c("BASE", "STRATA", "REGION")
)

# Specify imputation method
method <- rbmi::method_bayes(
  n_samples = N_IMPUTATIONS,
  control = rbmi::control_bayes(
    warmup = WARMUP,
    thin = THIN
  )
)

# Run analysis
ana_obj <- analyse_mi_data(
  data = ADMI,
  vars = vars,
  method = method,
  fun = ancova
)

# Pool results and tidy
pool_obj <- pool(ana_obj)
tidy_df <- tidy_pool_obj(pool_obj)

# View results
print(tidy_df)
#> # A tibble: 6 × 10
#>   parameter       description visit parameter_type lsm_type     est    se    lci
#>   <chr>           <chr>       <chr> <chr>          <chr>      <dbl> <dbl>  <dbl>
#> 1 trt_Week 24     Treatment … Week… trt            <NA>     -2.17   0.182 -2.53 
#> 2 lsm_ref_Week 24 Least Squa… Week… lsm            ref       0.0782 0.131 -0.179
#> 3 lsm_alt_Week 24 Least Squa… Week… lsm            alt      -2.09   0.126 -2.34 
#> 4 trt_Week 48     Treatment … Week… trt            <NA>     -3.81   0.256 -4.31 
#> 5 lsm_ref_Week 48 Least Squa… Week… lsm            ref       0.0481 0.185 -0.316
#> 6 lsm_alt_Week 48 Least Squa… Week… lsm            alt      -3.76   0.176 -4.11 
#> # ℹ 2 more variables: uci <dbl>, pval <dbl>

Datasets

The package includes two example datasets for demonstrating imputation and analysis:

  • ADEFF: An example efficacy dataset for with missing data.
  • ADMI: A large multiple imputation dataset with 100,000 rows and multiple visits, treatment arms, and stratification variables.

Use ?ADEFF and ?ADMI to view full dataset documentation.

Utilities

Key exported functions include:

  • analyse_mi_data(): Applies an analysis function (e.g., ANCOVA) to all imputed datasets.
  • tidy_pool_obj(): Tidies and annotates pooled results for reporting.
  • get_imputed_data(): Extracts long-format imputed datasets with original subject IDs mapped.

These utilities wrap standard rbmi workflows for improved reproducibility and interpretability.

Development Status

This package is experimental and under active development. Feedback and contributions are welcome via GitHub issues or pull requests.

Copy Link

Version

Install

install.packages('rbmiUtils')

Monthly Downloads

220

Version

0.1.8

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Mark Baillie

Last Published

January 24th, 2026

Functions in rbmiUtils (0.1.8)

as_analysis2

Construct an rbmi analysis object
analyse_mi_data

Apply Analysis Function to Multiple Imputed Datasets
gcomp_binary

Utility function for Generalized G-computation for Binary Outcomes
ADMI

Example multiple imputation trial dataset
ADEFF

Example efficacy trial dataset
get_imputed_data

Get Imputed Data Sets as a data frame
gcomp_responder_multi

G-computation for a Binary Outcome at Multiple Visits
tidy_pool_obj

Tidy and Annotate a Pooled Object for Publication
rbmiUtils-package

rbmiUtils: Utility Functions to Support and Extend the 'rbmi' Package
gcomp_responder

G-computation Analysis for a Single Visit
as_simple_formula2

Convert character variable list to formula
extract_covariates2

Extract variable names from model terms