title: Run linear model in a powerset of variables
body: <p>I am trying to get a data frame with different variables and run a linear model for each combination of those variables. </p>
  
  <p>A simple example is:</p>
  
  <pre><code>names &lt;- c("Var1", "Var2", "Var3") 
  vars &lt;- ggm::powerset(names, sort = T, nonempty = T) 
  </code></pre>
  
  <p>The <code>powerset</code> function gives me all the combinations of the 3 variables -- a list with 7 elements, each element is of type character. (the actual code I am trying to run has 16 variables, that's why I don´t want to manually write each of the models).</p>
  
  <p>What I would like to do now is run the models in each of these combinations of variables. For now, I have written the following code (it does not work, but might be a good start):</p>
  
  <pre><code>i &lt;- 1
  for (dep_var in vars){
    assign(paste0("modelo", i), lm(lapply(paste("Y", dep_var, sep = "~"), formula), 
    data = data))
    i &lt;- i+1
  }
  </code></pre>
  
  <p>Ultimately, I would like to create different models and select the best model from a combination of in sample AIC and BIC and out of sample MAE and RMSE. </p>
  
  <p>Thank you very much! Any help is appreciated!</p>