This function works by performing the following steps:
Extract a dataset from the imputations object.
Apply any delta adjustments as specified by the delta argument.
Run the analysis function fun on the dataset.
Repeat steps 1-3 across all of the datasets inside the imputations
object.
Collect and return all of the analysis results.
The analysis function fun must take a data.frame as its first
argument. All other options to rbmi_analyse() are passed onto fun
via ....
fun must return a named list with each element itself being a
list containing a single
numeric element called est (or additionally se and df if
you had originally specified the method_bayes() or method_approxbayes() functions from the rbmi package)
i.e.:
myfun <- function(dat, ...) {
mod_1 <- lm(data = dat, outcome ~ group)
mod_2 <- lm(data = dat, outcome ~ group + covar)
x <- list(
trt_1 = list(
est = coef(mod_1)[['group']], # Use [[ ]] for safety
se = sqrt(vcov(mod_1)['group', 'group']), # Use ['','']
df = df.residual(mod_1)
),
trt_2 = list(
est = coef(mod_2)[['group']], # Use [[ ]] for safety
se = sqrt(vcov(mod_2)['group', 'group']), # Use ['','']
df = df.residual(mod_2)
)
)
return(x)
}
Please note that the vars$subjid column (as defined in the original call to
the draws() function from the rbmi package) will be scrambled in the data.frames that are provided to fun.
This is to say they will not contain the original subject values and as such
any hard coding of subject ids is strictly to be avoided.
By default fun is the rbmi_ancova() function.
Please note that this function
requires that a vars object, as created by the set_vars() function from the rbmi package, is provided via
the vars argument e.g. rbmi_analyse(imputeObj, vars = set_vars(...)). Please
see the documentation for rbmi_ancova() for full details.
Please also note that the theoretical justification for the conditional mean imputation
method (method = method_condmean() in the draws() function from the rbmi package) relies on the fact that ANCOVA is
a linear transformation of the outcomes.
Thus care is required when applying alternative analysis functions in this setting.
The delta argument can be used to specify offsets to be applied
to the outcome variable in the imputed datasets prior to the analysis.
This is typically used for sensitivity or tipping point analyses. The
delta dataset must contain columns vars$subjid, vars$visit (as specified
in the original call to the draws() function from the rbmi package) and delta. Essentially this data.frame
is merged onto the imputed dataset by vars$subjid and vars$visit and then
the outcome variable is modified by:
imputed_data[[vars$outcome]] <- imputed_data[[vars$outcome]] + imputed_data[['delta']]
Please note that in order to provide maximum flexibility, the delta argument
can be used to modify any/all outcome values including those that were not
imputed. Care must be taken when defining offsets. It is recommend that you
use the helper function delta_template() from the rbmi package to define the delta datasets as
this provides utility variables such as is_missing which can be used to identify
exactly which visits have been imputed.