Combining DoParrallel and R2mlwin
Posted: Sat Oct 10, 2015 3:38 am
Hi
I am trying to work with the doParallel package (for multicore use) and R2mlwin. However, I am not able to pass the model specification as a list object via doParallel to the runmlwin function. I believe that the problems lay in how the list is defined:
# (1) settings
library(doParallel)
library(R2MLwiN)
cl <- makeCluster(3)
registerDoParallel(cl) # register the cores
# (2) define the three models to be passed to R2mlwin via doParallel
flist<-list(c(logit(AbsolutDep, cons) ~ 1 + (1 | country) , D = "Binomial", estoptions = list(EstM = 0), data = dfsm),
c(logit(AbsolutDep, cons) ~ 1 + DisVic2 + (1 | country) , D = "Binomial", estoptions = list(EstM = 0), data = dfsm),
c(logit(AbsolutDep, cons) ~ 1 + DisVic2 + (1 | country) , D = "Binomial", estoptions = list(EstM = 0), data = dfsm))
result <-foreach(i=1:3, .packages="R2MLwiN", .errorhandling=c('pass')) %dopar% {
runMLwiN(flist[])
}
# (3) doParallel seems to pass the list to runMLwiN. But runMLwiN returns the following error:
> result
[[1]]
<simpleError in parse(text = x, keep.source = FALSE): <text>:2:0: unexpected end of input
1: ~
^>
[[2]]
<simpleError in parse(text = x, keep.source = FALSE): <text>:2:0: unexpected end of input
1: ~
^>
[[3]]
<simpleError in parse(text = x, keep.source = FALSE): <text>:2:0: unexpected end of input
1: ~
^>
# (4) This is how the runMLwiN function should be specified:
runMLwiN(logit(AbsolutDep, cons) ~ 1 + (1 | country) , D = "Binomial", estoptions = list(EstM = 0), data = dfsm)
# (5) My hypothesis is that there is something wrong in how I define the flist object above since when I initiate runMLwiN but now with the concatenate c(), I get the same error as above:
> runMLwiN(c(logit(AbsolutDep, cons) ~ 1 + (1 | country) , D = "Binomial", estoptions = list(EstM = 0), data = dfsm))
Error in parse(text = x, keep.source = FALSE) :
<text>:2:0: unexpected end of input
1: ~
^
# (6) I guess, therefore, it is a matter of how I am passing the list via doParrallel to rrunMLwinN. I have tried various other specifications but cannot get it to work.
Many thanks for your guidance
Adel
I am trying to work with the doParallel package (for multicore use) and R2mlwin. However, I am not able to pass the model specification as a list object via doParallel to the runmlwin function. I believe that the problems lay in how the list is defined:
# (1) settings
library(doParallel)
library(R2MLwiN)
cl <- makeCluster(3)
registerDoParallel(cl) # register the cores
# (2) define the three models to be passed to R2mlwin via doParallel
flist<-list(c(logit(AbsolutDep, cons) ~ 1 + (1 | country) , D = "Binomial", estoptions = list(EstM = 0), data = dfsm),
c(logit(AbsolutDep, cons) ~ 1 + DisVic2 + (1 | country) , D = "Binomial", estoptions = list(EstM = 0), data = dfsm),
c(logit(AbsolutDep, cons) ~ 1 + DisVic2 + (1 | country) , D = "Binomial", estoptions = list(EstM = 0), data = dfsm))
result <-foreach(i=1:3, .packages="R2MLwiN", .errorhandling=c('pass')) %dopar% {
runMLwiN(flist[])
}
# (3) doParallel seems to pass the list to runMLwiN. But runMLwiN returns the following error:
> result
[[1]]
<simpleError in parse(text = x, keep.source = FALSE): <text>:2:0: unexpected end of input
1: ~
^>
[[2]]
<simpleError in parse(text = x, keep.source = FALSE): <text>:2:0: unexpected end of input
1: ~
^>
[[3]]
<simpleError in parse(text = x, keep.source = FALSE): <text>:2:0: unexpected end of input
1: ~
^>
# (4) This is how the runMLwiN function should be specified:
runMLwiN(logit(AbsolutDep, cons) ~ 1 + (1 | country) , D = "Binomial", estoptions = list(EstM = 0), data = dfsm)
# (5) My hypothesis is that there is something wrong in how I define the flist object above since when I initiate runMLwiN but now with the concatenate c(), I get the same error as above:
> runMLwiN(c(logit(AbsolutDep, cons) ~ 1 + (1 | country) , D = "Binomial", estoptions = list(EstM = 0), data = dfsm))
Error in parse(text = x, keep.source = FALSE) :
<text>:2:0: unexpected end of input
1: ~
^
# (6) I guess, therefore, it is a matter of how I am passing the list via doParrallel to rrunMLwinN. I have tried various other specifications but cannot get it to work.
Many thanks for your guidance
Adel