I am doing a capstone project. As such I have two datasets to work with; training data and testing data. Both datasets have missing values. My goal is to do that with mice. When preparing the training data, I:
Init = mice(data = Values, maxit = 0) Imputed = mice(data = Values, method = 'cart', predictorMatrix = Init$predictorMatrix, m = 1) Imputed = complete(Imputed) Values = Imputed
This works great. Subsequent to this code I can build my regression model no issues.
My problem is - I am doing this in a function that:
Output = list(TrainingSet, TestingSet, Init) return(Output)
When the function (called from my main module) completes - I attempt to unpack this list via:
TrainingSet <<- data.frame(TrainingData)
TestingSet <<- data.frame(TrainingData)
Init <<- as.mids(TrainingData)
The two datasets unpack successfully - but the init object does not. I get Error in data[, .imp] : incorrect number of dimensions.
When I do a str(TrainingData) I get a list of 1 containing a list of 17. I get the same thing if I str(TrainingData). The init object - when I create it in the function - is a single list of 17.
How can I pass this object back from a function?
My end goal - if it matters - is to use the predictorMatrix created when Imputing the training data when I am imputing the testing data - which also contains missing variables.
Any help will be greatly appreciated. Thank You.