+Now theta is a list with three slots:
+ * $p$: estimated proportions,
+ * $\beta$: estimated regression matrix,
+ * $b$: estimated bias.
+
+### Monte-Carlo and bootstrap
+
+The package provides a function to compare methods on several computations on random data.
+It takes in input a list of parameters, then a list of functions which output some quantities
+(on the first example, our "computeMu()" method versus flexmix way of estimating directions),
+and finally a method to prepare the arguments which will be given to the functions in the
+list just mentioned; this allows to run Monte-Carlo estimations with the exact same samples
+for each compared method. The two last arguments to "multiRun()" control the number of runs,
+and the number of cores (using the package parallel).
+
+```{r, results="show", include=TRUE, echo=TRUE}
+beta <- matrix(c(1,-2,3,1), ncol=2)
+io <- generateSampleIO(n=1000, p=1/2, beta=beta, b=c(0,0), "logit")
+mu <- normalize(beta)
+
+# Example 1: bootstrap + computeMu, morpheus VS flexmix; assumes fargs first 3 elts X,Y,K
+mr1 <- multiRun(list(X=io$X,Y=io$Y,optargs=list(K=2,jd_nvects=0)), list(
+ # morpheus
+ function(fargs) {
+ library(morpheus)
+ ind <- fargs$ind
+ computeMu(fargs$X[ind,],fargs$Y[ind],fargs$optargs)
+ },
+ # flexmix
+ function(fargs) {
+ library(flexmix)
+ source("../patch_Bettina/FLXMRglm.R")
+ ind <- fargs$ind
+ K <- fargs$optargs$K
+ dat = as.data.frame( cbind(fargs$Y[ind],fargs$X[ind,]) )
+ out = refit( flexmix( cbind(V1, 1 - V1) ~ 0+., data=dat, k=K,
+ model=FLXMRglm(family="binomial") ) )
+ normalize( matrix(out@coef[1:(ncol(fargs$X)*K)], ncol=K) )
+ } ),
+ prepareArgs = function(fargs,index) {
+ # Always include the non-shuffled dataset
+ if (index == 1)
+ fargs$ind <- 1:nrow(fargs$X)
+ else
+ fargs$ind <- sample(1:nrow(fargs$X),replace=TRUE)
+ fargs
+ }, N=10, ncores=3)
+# The result is correct up to matrices columns permutations; align them:
+for (i in 1:2)
+ mr1[[i]] <- alignMatrices(mr1[[i]], ref=mu, ls_mode="exact")
+```