Apply a Function to Multiple Imputations

DESCRIPTION:

Returns an miVariable list as the result of applying a function to multiple imputations of its input.

USAGE:

miApply(X, FUN, ..., simplify = F, X.frame1) 

REQUIRED ARGUMENTS:

X
an object containing multiple imputations (see ).
FUN
a function.

OPTIONAL ARGUMENTS:

...
additional arguments to the function; they are passed unchanged (including their names) to each call of FUN. These may not contain multiple imputations.
simplify
logical, if TRUE the result is simplified if its imputations are identical.
X.frame1
list with named components, or mi object whose imputations are such lists.

VALUE:

an object of class miList, for which each component contains the result of evaluating expr with a single set of multiple imputations.

If simplify=TRUE and all components are identical, then just one component is returned (i.e. the miList is simplified to an ordinary object).

SIDE EFFECTS:

If X.frame1 is supplied, then objects are saved on frame 1.

DETAILS:

Each imputation of X is passed as the first (unnamed) argument to FUN, together with the additional (possibly named) arguments. The result is saved as one component in the returned list.

If X.frame1 is supplied, then each imputation of X.frame1 is extracted and each component is saved in frame 1 before FUN is called with the corresponding imputation of X . At least one of X and X.frame1 must contain multiple imputations. This argument is useful for certain modeling functions, which expect imputations of the original data frame to be available when the function is called.

SEE ALSO:

, , , .

EXAMPLES:

x <- cholesterolImpExample[[3]] 
miApply(x, mean, trim = .2) 
miEval(mean(x, trim = .2)) 
miEval(mean(cholesterolImpExample[[3]], trim = .2)) 
# Compare miApply & miEval, use of X.frame1 
fit1 <- miEval(glm(chol14 ~ ., data = cholesterolImpExample)) 
fit2 <- miApply(cholesterolImpExample, 
                function(x) glm(chol14 ~ ., data = x)) 
fit1[[3]]$call # Compare the calls.  This one is fine. 
fit2[[3]]$call # This one is not.  Use X.frame1 later if needed. 
rm(x)  # avoid accidentally using unrelated "x" 
miEval(summary(fit1)) 
miApply(fit2, summary)  # same 
miEval(predict(fit1, type = "terms")) 
# miApply(fit2, predict, type = "terms") # fails, x not found 
miApply(fit2, predict, type = "terms", 
        X.frame1 = list(x = cholesterolImpExample)) 
# Now matches the miEval result 
# Had to use X.frame1 to match the original data to the name x. 
# (and to cause each set of imputations to be used in turn).