I have multiple datasets for which I need to execute matchit. It's all just one dataset which I have divided into multiple datasets.
datalist <-split(data, data$column)
## split the data based on the column, the matching needs to happen within the same column value strata
## Example : 13 datasets in the list datalist
# Register parallel cluster with cores [one sub-dataset one core process]
cl <- makeCluster(length(datalist))
registerDoParallel(cl)
## I have 96 cores available
output <- foreach(i=1:length(datalist), .combine = 'rbind') %dopar% {
matchingresults <- matchit(treatment ~ a,
data=datalist[[i]],
#method = "nearest",
distance='euclidean',
exact= ~ c + b,
replace=FALSE)
matcheddata <- match.data(matchingresults)
matcheddata
}
I was hoping this will create 13 R sessions and run matching on each of the 13 datasets on a new core but it doesn't. It only creates one worker session.
How can I parallelize matching which uses the same logic on different datasets?