title: Parallel looping over multiple lists lme4
body: <p>I am trying to run multi-level models over a number of variables. I have two lists of variables - outcome and response. What I'm having difficulty with is setting up the lapply command to run each element of the list in parallel. So the first element of the list "outcome" runs at the same time as the first element of the list "response". Then for the second element of the list "outcome", the second element of the list "response" is called. </p>
  
  <p>I have been able to combine 2 lapply commands but this gives me every combination of each element from the outcome and response list which is not ideal. I can manually extract the elements I want but is there another way to achieve this? </p>
  
  <pre class="lang-r prettyprint-override"><code>#Define random intercept
  random_intercepts &lt;- "(1|clusters)"
  
  #For each of the 4 outcome variables, define the response variables
  water_imp_vars &lt;- c("fish_factor", "num_childrenunder5", "quintile_nowashnomat_fac")
  less5_vars &lt;- c("fish_factor", "num_hh_members", "num_childrenunder5")
  san_imp_vars &lt;- c("fish_factor", "num_hh_members", "num_childrenunder5", "quintile_nowashnomat_fac")
  housing_imp_vars &lt;- c("fish_factor","num_hh_members", "num_childrenunder5", "quintile_nowashnomat_fac")
  
  #Combine all repsonse variables into 1 list
  all_response &lt;- list(water_imp_vars, less5_vars, san_imp_vars, housing_imp_vars)
  
  #List of outcomes 
  outcomes &lt;- c("water_imp", "less_than_5", "san_imp", "housing_imp")
  
  
  all_models &lt;- lapply(setNames(outcomes, outcomes), function(var) {
    lapply(all_response, function(var2) {
      fixed &lt;- paste0(var2, collapse= "+")
      formula &lt;- as.formula(paste(var, "~", fixed, "+", random_intercepts))
      glmer(formula, hr_analysis_dataset, family='binomial', nAGQ = 0)
    })
  })
  </code></pre>
  
  <p>Here is some of the output from the all_models variable. </p>
  
  <pre class="lang-r prettyprint-override"><code>$water_imp
  $water_imp[[1]]
  water_imp ~ fish_factor + num_childrenunder5 + quintile_nowashnomat_fac + 
      (1 | clusters)
  &lt;environment: 0x0000000017ecdd58&gt;
  
  $water_imp[[2]]
  water_imp ~ fish_factor + num_hh_members + num_childrenunder5 + 
      (1 | clusters)
  &lt;environment: 0x0000000017ed1858&gt;
  
  $water_imp[[3]]
  water_imp ~ fish_factor + num_hh_members + num_childrenunder5 + 
      quintile_nowashnomat_fac + (1 | clusters)
  &lt;environment: 0x0000000017ed5f20&gt;
  
  $water_imp[[4]]
  water_imp ~ fish_factor + num_hh_members + num_childrenunder5 + 
      quintile_nowashnomat_fac + (1 | clusters)
  &lt;environment: 0x0000000017ed86a0&gt;
  
  </code></pre>
  
  <p>I am only interested in the first combination for the first outcome variable --</p>
  
  <pre class="lang-r prettyprint-override"><code>water_imp ~ fish_factor + num_childrenunder5 + quintile_nowashnomat_fac + 
      (1 | clusters)
  </code></pre>
  
  <p>and then for the second outcome variable, I am interested in the second combination </p>
  
  <pre class="lang-r prettyprint-override"><code>less_than_5 ~ fish_factor + num_hh_members + num_childrenunder5 + 
      (1 | clusters)
  </code></pre>
  
  <p>Although it is not a lot of work to extract the correct combination, I am also planning to run this analysis for a number of countries so this problem will continue to grow once additional levels are added. </p>
  
  <p>Any help would be very much appreciated</p>