Learn R Programming

rbmiUtils (version 0.3.0)

prepare_data_ice: Prepare Intercurrent Event Data

Description

Builds a data_ice data.frame from a column in the dataset that flags intercurrent events. For each subject, the first visit (by factor level order) where the flag is TRUE is used as the ICE visit.

Usage

prepare_data_ice(data, vars, ice_col, strategy)

Value

A data.frame with columns corresponding to vars$subjid, vars$visit, and vars$strategy, suitable for passing to rbmi::draws().

Arguments

data

A data.frame containing the analysis dataset.

vars

A vars object as created by rbmi::set_vars().

ice_col

Character string naming the column in data that indicates ICE occurrence. Accepted values are logical (TRUE/FALSE), character ("Y"/"N"), or numeric (1/0).

strategy

Character string specifying the imputation strategy to assign. Must be one of "MAR", "CR", "JR", "CIR", or "LMCF".

See Also

  • rbmi::draws() which accepts the data_ice output from this function

  • validate_data() to check data before imputation

  • summarise_missingness() to understand missing data patterns

Examples

Run this code
library(rbmi)

dat <- data.frame(
  USUBJID = factor(rep(c("S1", "S2", "S3"), each = 3)),
  AVISIT = factor(rep(c("Week 4", "Week 8", "Week 12"), 3),
                  levels = c("Week 4", "Week 8", "Week 12")),
  TRT = factor(rep(c("Placebo", "Drug A", "Drug A"), each = 3)),
  CHG = rnorm(9),
  DISCFL = c("N","N","N", "N","Y","Y", "N","N","Y")
)

vars <- set_vars(
  subjid = "USUBJID",
  visit = "AVISIT",
  group = "TRT",
  outcome = "CHG"
)

ice <- prepare_data_ice(dat, vars, ice_col = "DISCFL", strategy = "JR")
print(ice)

Run the code above in your browser using DataLab