Learn R Programming

rbmiUtils (version 0.3.0)

analyse_mi_data: Apply Analysis Function to Multiple Imputed Datasets

Description

This function applies an analysis function (e.g., ANCOVA) to imputed datasets and stores the results for later pooling. It is designed to work with multiple imputed datasets and apply a given analysis function to each imputation iteration.

Usage

analyse_mi_data(
  data = NULL,
  vars = NULL,
  method = NULL,
  fun = rbmi::ancova,
  delta = NULL,
  ...
)

Value

An object of class analysis containing the results from applying the analysis function to each imputed dataset. Pass this to rbmi::pool() to obtain pooled estimates.

Arguments

data

A data frame containing the imputed datasets. The data frame should include a variable (e.g., IMPID) that identifies distinct imputation iterations. Typically obtained from get_imputed_data() or expand_imputed_data().

vars

A list specifying key variables used in the analysis (e.g., subjid, visit, group, outcome). Created using rbmi::set_vars(). Required.

method

A method object specifying the imputation method used (e.g., Bayesian imputation). Created using rbmi::method_bayes(), rbmi::method_approxbayes(), or rbmi::method_condmean(). Required.

fun

A function that will be applied to each imputed dataset. Defaults to rbmi::ancova. Other options include gcomp_responder_multi() for binary outcomes. Must be a valid analysis function.

delta

A data.frame used for delta adjustments, or NULL if no delta adjustments are needed. Defaults to NULL. Must contain columns matching vars$subjid, vars$visit, vars$group, and a delta column.

...

Additional arguments passed to the analysis function fun.

Details

The function loops through distinct imputation datasets (identified by IMPID), applies the provided analysis function fun, and stores the results for later pooling. If a delta dataset is provided, it will be merged with the imputed data to apply the specified delta adjustment before analysis.

Workflow:

  1. Prepare imputed data using get_imputed_data() or expand_imputed_data()

  2. Define variables using rbmi::set_vars()

  3. Call analyse_mi_data() to apply analysis to each imputation

  4. Pool results using rbmi::pool()

  5. Tidy results using tidy_pool_obj()

See Also

  • rbmi::analyse() which this function wraps

  • rbmi::pool() for pooling the analysis results

  • The rbmi quickstart vignette

  • tidy_pool_obj() to format pooled results for publication

  • get_imputed_data() to extract imputed datasets from rbmi objects

  • expand_imputed_data() to reconstruct full imputed data from reduced form

  • gcomp_responder_multi() for binary outcome analysis

  • validate_data() to check data before imputation

Examples

Run this code
# Example usage with an ANCOVA function
library(dplyr)
library(rbmi)
library(rbmiUtils)
set.seed(123)
data("ADMI")

# Convert key columns to factors
ADMI$TRT <- factor(ADMI$TRT, levels = c("Placebo", "Drug A"))
ADMI$USUBJID <- factor(ADMI$USUBJID)
ADMI$AVISIT <- factor(ADMI$AVISIT)

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

# Specify the imputation method (Bayesian) - need for pool step
 method <- rbmi::method_bayes(
 n_samples = 20,
 control = rbmi::control_bayes(
   warmup = 20,
   thin = 1
   )
 )

# Perform ANCOVA Analysis on Each Imputed Dataset
ana_obj_ancova <- analyse_mi_data(
  data = ADMI,
  vars = vars,
  method = method,
  fun = ancova,  # Apply ANCOVA
  delta = NULL   # No sensitivity analysis adjustment
)

Run the code above in your browser using DataLab