title: GNU R ANOVA with aov(): Multiple variables as factors vs. one variable with multiple factors
body: <p>Currently, I am evaluating a questionary with a repeated measure design. I would like to do an analysis of variance. However, I came across an issue fitting the model.
  Why does it make a difference whether I model factors either as
  Multiple variables (each representing a single factor), or
  Within one variable (where each factor is represented by a value of the variable)?</p>
  
  <p>In order to illustrate my question, I chose the following example (adapted from <a href="http://ww2.coastal.edu/kingw/statistics/R-tutorials/repeated.html" rel="nofollow" title="this tutorial">this tuorial</a>):</p>
  
  <pre><code>### Data with repeated measures
  groceries &lt;- data.frame(
    c("lettuce","potatoes","milk","eggs","bread","cereal",
      "ground.beef","tomato.soup","laundry.detergent","aspirin"),
    c(1.17,1.77,1.49,0.65,1.58,3.13,2.09,0.62,5.89,4.46),
    c(1.78,1.98,1.69,0.99,1.70,3.15,1.88,0.65,5.99,4.84),
    c(1.29,1.99,1.79,0.69,1.89,2.99,2.09,0.65,5.99,4.99),
    c(1.29,1.99,1.59,1.09,1.89,3.09,2.49,0.69,6.99,5.15))
  colnames(groceries) &lt;- c("subject","storeA","storeB","storeC","storeD")
  
  ### Rearranging data for ANOVA (r); 'store' is the variable with 4 factors
  groceries &lt;- cbind(stack(groceries[,2:5]), rep(groceries$subject,4))
  colnames(groceries) &lt;- c("price", "store", "subject")
  
  ### Adding 4 columns for each factor -&gt; thus, 4 boolean variables  
  factorLookup &lt;- as.character(unique(groceries$store))
  groceries &lt;- cbind(groceries, 
                      sapply(1 : length(factorLookup), 
                             function(x) groceries$store ==  factorLookup[x]))
  names(groceries)[4:7] &lt;- factorLookup
  
  ### ANOVA using variable 'store' as factor
  aov.1var &lt;- aov(price ~ store + Error(subject/store), data=groceries)
  summary(aov.1var)
  
  ### ANOVA using 4 factor variables
  aov.4fact &lt;- aov(price ~ storeA * storeB * storeC * storeD 
                 + Error(subject/(storeA * storeB * storeC * storeD)), data=groceries)
  summary(aov.4fact)
  </code></pre>
  
  <p>These are the results, which are clearly not the same for both approaches. In addition, they come with a warning for the multiple variable approach:</p>
  
  <pre><code>&gt; ### ANOVA using variable 'store' as factor
  &gt; aov.1var &lt;- aov(price ~ store + Error(subject/store), data=groceries)
  &gt; summary(aov.1var)
  
  Error: subject
            Df Sum Sq Mean Sq F value Pr(&gt;F)
  Residuals  9  115.2    12.8               
  
  Error: subject:store
            Df Sum Sq Mean Sq F value Pr(&gt;F)  
  store      3 0.5859 0.19529   4.344 0.0127 *
  Residuals 27 1.2137 0.04495                 
  ---
  Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  &gt; 
  &gt; ### ANOVA using 4 factor variables
  &gt; aov.4fact &lt;- aov(price ~ storeA * storeB * storeC * storeD 
  +                + Error(subject/(storeA * storeB * storeC * storeD)), data=groceries)
  Warning message:
  In aov(price ~ storeA * storeB * storeC * storeD + Error(subject/(storeA *  :
    Error() Modell ist singulär
  &gt; summary(aov.4fact)
  
  Error: subject
            Df Sum Sq Mean Sq F value Pr(&gt;F)
  Residuals  9  115.2    12.8               
  
  Error: subject:storeA
            Df Sum Sq Mean Sq F value Pr(&gt;F)   
  storeA     1 0.3763  0.3763   16.02 0.0031 **
  Residuals  9 0.2115  0.0235                  
  ---
  Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  
  Error: subject:storeB
            Df Sum Sq Mean Sq F value Pr(&gt;F)
  storeB     1 0.0290 0.02904    0.54  0.481
  Residuals  9 0.4842 0.05380               
  
  Error: subject:storeC
            Df Sum Sq Mean Sq F value Pr(&gt;F)
  storeC     1 0.1805 0.18050   3.135   0.11
  Residuals  9 0.5181 0.05757  
  </code></pre>
  
  <p>Which keeps me puzzled: Both approaches would lead to the same results using a linear mixed model (e.g. lme {nlme}). Why does not the same apply for an ANOVA?</p>
  
  <p>Maybe something about my general understanding of ANOVA is wrong. Why isn't there any F-value output for each factor using the single variable approach?!</p>
  
  <p>Any help appreciated a lot!</p>