I'm currently doing causal mediation with the CMAverse R package. The 'cmest' function has the ability to impute missing data and the option of specifying additional arguments via an "args_mice" argument. I want to include additional arguments including a predictor matrix which will allow missing values for the variables in the model to be imputed using information from other variables in the study but are not included within the mediation model.
Here is example code which show the additional arguments wanting to be passed through the "args_mice" argument.
Note:
X=binary
Y=continuous
M1, M2, M3 = continuous
C1, C2 =continuous
Model <- cmest(data = data, model = "rb", outcome = "Y",
exposure = "X", mediator = c("M1", "M2", "M3"),
basec = c("C1", "C2"),EMint = TRUE,
mreg = list("linear", "linear", "linear"), yreg = "linear", astar = 0, a = 1, mval = list(12, 13, 14),
estimation = "imputation", inference = "bootstrap", nboot = 500, boot.ci.type = "bca",
multimp = TRUE, args_mice = list (m=5, predictorMatrix = PredMatrix_alldata, maxit=10))
When running the model the following error is shown:
Error in `[.data.frame`(data, , yvar) : undefined columns selected
The model runs as expected when the predictorMatrix= PredMatrix_alldata argument is not included in the list. Therefore I know the issues is related to the predictor matrix.
PredMatrix_alldata is correctly formatted with "0"s and "1" and is a matrix of 46 variables which I want to use for the imputation for the specified model
I'm unsure if the error is due to the predictor matrix having more variables than are in the model, however, that is what I want to do for the imputation. Use variables outside those in the model to impute missing data for variables within the model.
Any help better understanding the error or how to include the predictor matrix is appreciated.