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,
...
)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 fromget_imputed_data()orexpand_imputed_data().- vars
A list specifying key variables used in the analysis (e.g.,
subjid,visit,group,outcome). Created usingrbmi::set_vars(). Required.- method
A method object specifying the imputation method used (e.g., Bayesian imputation). Created using
rbmi::method_bayes(),rbmi::method_approxbayes(), orrbmi::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.frameused for delta adjustments, orNULLif no delta adjustments are needed. Defaults toNULL. Must contain columns matchingvars$subjid,vars$visit,vars$group, and adeltacolumn.- ...
Additional arguments passed to the analysis function
fun.
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.
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:
Prepare imputed data using
get_imputed_data()orexpand_imputed_data()Define variables using
rbmi::set_vars()Call
analyse_mi_data()to apply analysis to each imputationPool results using
rbmi::pool()Tidy results using
tidy_pool_obj()
See also
tidy_pool_obj()to format pooled results for publicationget_imputed_data()to extract imputed datasets from rbmi objectsexpand_imputed_data()to reconstruct full imputed data from reduced formgcomp_responder_multi()for binary outcome analysisvalidate_data()to check data before imputation
Examples
# Example usage with an ANCOVA function
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
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
)
#> Warning: Data contains 100 imputations but method expects 20. Using first 20 imputations.