Modify an Expression for Multiple Imputation Evaluation

DESCRIPTION:

Create a modified version of an expression, replacing object names with code to extract or replace an imputation from that object.

USAGE:

miModifyExpr(expr, k, vnames = NULL) 

REQUIRED ARGUMENTS:

expr
an expression.
k
an integer.

OPTIONAL ARGUMENTS:

vnames
character vector containing names that should be replaced in the expression; if NULL then all names are replaced.

VALUE:

a modified expression, such that variable names (e.g. "X") are replaced by an expression (e.g. miSubscript(X,k)).

DETAILS:

This function is used by miEval. It is not intended for direct use.

SEE ALSO:

, , , , .

EXAMPLES:

miModifyExpr(Quote(a <- x+y), 3, c("a", "x")) 
# If x contains three imputations, then the following 
# does "a <- mean(x, trim = .2)" independently for each imputation: 
a <- miList(list(0,0,0,0,0))    # a must exist & be an miList 
x <- cholesterolImpExample[[3]] 
for(i in 1:5) eval(miModifyExpr( 
     Quote(a <- mean(x, trim = .2)), i, c("a","x"))) 
a 
# Same result, much simpler, just use miEval: 
miEval(mean(x, trim = .2))