title: How to pass the 'object' argument dynamically to anova() function
body: <p>I am struggling to write a script which allows for a more flexible approach to compare different linear mixed-effect models making use of the <code>lme4</code> or <code>nlme</code> package. As I do not want to adjust the script for each and every model I add or drop, I am looking for a <strong>dynamic</strong> approach. Doing so I would only have to adjust one variable which contains character strings of the model formulas.</p>
  
  <p>This works fine unless <code>anova()</code> comes in. <code>anova()</code> does not accept a <strong>list</strong> of elements containing the appropriate classes:</p>
  
  <pre><code>###### Here is my problem
  # comparing models by means of ANOVA
  anova(lme.lst)                                  #### --&gt; does not work
  anova(lme.lst[[1]], lme.lst[[2]], lme.lst[[3]]) #### would work but kills the dynamic approach
  ######
  </code></pre>
  
  <p>I did not figure a neat way to decompose the list and pass multiple arguments to the <code>anova()</code> function. I tried <code>unlist()</code> without any success.</p>
  
  <p>Here is a minimal example (adapted from <a href="http://cran.r-project.org/web/packages/lme4/lme4.pdf" rel="nofollow" title="lme4 reference manual p 8quot;">lme4 manual, p. 8</a>):</p>
  
  <pre><code>require(lme4)
  require(AICcmodavg)
  
  # Variable containing of strings in order to describe the fixed effect terms 
  # (wihout response/dependen variable)                                            ### should be orderd from
  callModel &lt;- c("angle ~ recipe + temp        + (1|recipe:replicate)",  # model1  ### small
                 "angle ~ recipe + temperature + (1|recipe:replicate)",  # model2  ### too                
                 "angle ~ recipe * temperature + (1|recipe:replicate)")  # model3  ### BIG
  
  # convert string array 'callFeVar' into a list of formulas
  callModel &lt;- sapply(callModel, as.formula)
  
  # create an empty list for safing the results of fitted model 
  lme.lst &lt;- list()
  # do model fitting in a loop and change list names
  for (i in 1 : length(callModel)) {
    lmeTmp &lt;- lmer(callModel[[i]], cake, REML= FALSE)
    lme.lst[i] &lt;- list(lmeTmp)
    names(lme.lst)[i] &lt;- deparse(callModel[[i]])
  }
  # remove temporary variable
  rm(lmeTmp)
  
  # summary of models
  lapply(lme.lst, summary)
  
  ###### Here is my problem
  # comparing models by means of ANOVA
  anova(lme.lst)                                  #### --&gt; does not work
  anova(lme.lst[[1]], lme.lst[[2]], lme.lst[[3]]) #### would work but kills the dynamic approach
  ######
  
  # comparing models by means of AICc
  aictab(lme.lst)                                 #### accepts list
  </code></pre>