title: rstatix anova_test in R gives contrast error despite more than 2 levels
body: <p>The following is subset of my data set:</p>
  <pre><code>structure(list(ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
  2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 
  5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L), .Label = c(&quot;5356&quot;, 
  &quot;5357&quot;, &quot;5358&quot;, &quot;5359&quot;, &quot;5360&quot;, &quot;5363&quot;, &quot;5373&quot;, &quot;5381&quot;, &quot;5383&quot;, 
  &quot;5386&quot;, &quot;5395&quot;, &quot;5397&quot;, &quot;5400&quot;, &quot;5401&quot;, &quot;5444&quot;, &quot;5445&quot;, &quot;5446&quot;, 
  &quot;5448&quot;, &quot;5450&quot;, &quot;5451&quot;, &quot;5454&quot;, &quot;5472&quot;, &quot;5473&quot;, &quot;5475&quot;, &quot;5476&quot;, 
  &quot;5477&quot;, &quot;5478&quot;, &quot;5480&quot;, &quot;5481&quot;, &quot;5483&quot;, &quot;5487&quot;, &quot;5494&quot;, &quot;5495&quot;, 
  &quot;5504&quot;, &quot;5505&quot;, &quot;5506&quot;, &quot;5507&quot;, &quot;5508&quot;, &quot;5509&quot;, &quot;5513&quot;, &quot;5514&quot;, 
  &quot;5515&quot;, &quot;5516&quot;, &quot;5517&quot;, &quot;5518&quot;, &quot;5519&quot;, &quot;5521&quot;, &quot;5523&quot;, &quot;5524&quot;, 
  &quot;5526&quot;, &quot;5527&quot;, &quot;5528&quot;, &quot;5544&quot;, &quot;5545&quot;, &quot;5546&quot;, &quot;5547&quot;, &quot;5551&quot;, 
  &quot;5552&quot;, &quot;5553&quot;, &quot;5554&quot;, &quot;5555&quot;, &quot;5558&quot;, &quot;5559&quot;, &quot;5560&quot;, &quot;5562&quot;, 
  &quot;5564&quot;, &quot;5566&quot;, &quot;5573&quot;, &quot;5574&quot;, &quot;5575&quot;, &quot;5576&quot;, &quot;5577&quot;, &quot;5578&quot;, 
  &quot;5579&quot;, &quot;5584&quot;, &quot;5585&quot;, &quot;5587&quot;, &quot;5588&quot;, &quot;5589&quot;, &quot;5591&quot;, &quot;5594&quot;, 
  &quot;5595&quot;, &quot;5604&quot;, &quot;5611&quot;, &quot;5612&quot;, &quot;5613&quot;, &quot;5615&quot;, &quot;5616&quot;, &quot;5619&quot;, 
  &quot;5620&quot;, &quot;5621&quot;, &quot;5622&quot;, &quot;5626&quot;, &quot;5627&quot;, &quot;5628&quot;, &quot;5631&quot;, &quot;5632&quot;, 
  &quot;5634&quot;, &quot;5635&quot;, &quot;5643&quot;, &quot;5652&quot;, &quot;5653&quot;, &quot;5654&quot;, &quot;5655&quot;, &quot;5656&quot;, 
  &quot;5657&quot;, &quot;5659&quot;, &quot;5660&quot;, &quot;5661&quot;, &quot;5664&quot;, &quot;5665&quot;, &quot;5666&quot;, &quot;5669&quot;, 
  &quot;5671&quot;, &quot;5672&quot;, &quot;5673&quot;, &quot;5678&quot;, &quot;5680&quot;, &quot;5688&quot;, &quot;5689&quot;, &quot;5690&quot;, 
  &quot;5691&quot;, &quot;5692&quot;, &quot;5698&quot;, &quot;5699&quot;, &quot;5700&quot;, &quot;5702&quot;, &quot;5703&quot;, &quot;5704&quot;, 
  &quot;5706&quot;, &quot;5708&quot;, &quot;5709&quot;, &quot;5710&quot;, &quot;5730&quot;, &quot;5731&quot;, &quot;5732&quot;, &quot;5733&quot;, 
  &quot;5734&quot;, &quot;5735&quot;, &quot;5739&quot;, &quot;5740&quot;, &quot;5741&quot;, &quot;5742&quot;, &quot;5743&quot;, &quot;5744&quot;, 
  &quot;5745&quot;, &quot;5746&quot;, &quot;5747&quot;, &quot;5748&quot;, &quot;5749&quot;, &quot;5750&quot;, &quot;5753&quot;, &quot;5754&quot;, 
  &quot;5755&quot;, &quot;5766&quot;, &quot;5767&quot;, &quot;5776&quot;, &quot;5777&quot;, &quot;5778&quot;, &quot;5779&quot;, &quot;5780&quot;, 
  &quot;5781&quot;, &quot;5787&quot;, &quot;5788&quot;, &quot;5789&quot;, &quot;5790&quot;, &quot;5791&quot;, &quot;5792&quot;, &quot;5793&quot;, 
  &quot;5797&quot;, &quot;5798&quot;, &quot;5799&quot;, &quot;5800&quot;, &quot;5801&quot;, &quot;5810&quot;, &quot;5811&quot;, &quot;5812&quot;, 
  &quot;5813&quot;, &quot;5814&quot;, &quot;5819&quot;, &quot;5820&quot;, &quot;5821&quot;, &quot;5822&quot;, &quot;5823&quot;, &quot;5824&quot;, 
  &quot;5825&quot;, &quot;5827&quot;, &quot;5828&quot;, &quot;5829&quot;, &quot;5830&quot;, &quot;5857&quot;, &quot;5859&quot;, &quot;5874&quot;, 
  &quot;5875&quot;, &quot;5876&quot;, &quot;5877&quot;, &quot;5878&quot;, &quot;5879&quot;, &quot;5883&quot;, &quot;5884&quot;, &quot;5886&quot;, 
  &quot;5887&quot;, &quot;5888&quot;, &quot;5889&quot;, &quot;5890&quot;, &quot;5892&quot;, &quot;5893&quot;, &quot;5896&quot;, &quot;5899&quot;, 
  &quot;5900&quot;, &quot;5909&quot;, &quot;5910&quot;, &quot;5918&quot;, &quot;5919&quot;, &quot;5920&quot;, &quot;5921&quot;, &quot;5922&quot;, 
  &quot;5923&quot;, &quot;5927&quot;, &quot;5929&quot;, &quot;5931&quot;, &quot;5932&quot;, &quot;5933&quot;, &quot;5934&quot;, &quot;5936&quot;, 
  &quot;5937&quot;, &quot;5941&quot;, &quot;5943&quot;, &quot;5944&quot;, &quot;5949&quot;, &quot;5950&quot;, &quot;5951&quot;, &quot;5952&quot;, 
  &quot;5956&quot;, &quot;5957&quot;, &quot;5958&quot;, &quot;5959&quot;, &quot;5971&quot;, &quot;5972&quot;, &quot;5973&quot;, &quot;5976&quot;, 
  &quot;5979&quot;, &quot;5980&quot;, &quot;5981&quot;, &quot;6001&quot;, &quot;6002&quot;, &quot;6003&quot;, &quot;6004&quot;, &quot;6005&quot;, 
  &quot;6009&quot;, &quot;6027&quot;, &quot;6028&quot;, &quot;6033&quot;, &quot;6042&quot;, &quot;6054&quot;, &quot;6063&quot;, &quot;6067&quot;, 
  &quot;6073&quot;, &quot;6076&quot;, &quot;6077&quot;, &quot;6078&quot;, &quot;6079&quot;, &quot;6080&quot;, &quot;6081&quot;, &quot;6082&quot;, 
  &quot;6083&quot;, &quot;6098&quot;, &quot;6102&quot;, &quot;6103&quot;, &quot;6104&quot;, &quot;6105&quot;, &quot;6106&quot;, &quot;6107&quot;, 
  &quot;6111&quot;, &quot;6119&quot;, &quot;6133&quot;, &quot;6146&quot;, &quot;6147&quot;, &quot;6157&quot;, &quot;6158&quot;, &quot;6160&quot;, 
  &quot;6161&quot;, &quot;6162&quot;, &quot;6163&quot;, &quot;6164&quot;, &quot;6165&quot;, &quot;6166&quot;, &quot;6167&quot;, &quot;6168&quot;, 
  &quot;6169&quot;, &quot;6170&quot;, &quot;6171&quot;, &quot;6172&quot;, &quot;6173&quot;, &quot;6174&quot;, &quot;6175&quot;, &quot;6190&quot;, 
  &quot;6193&quot;, &quot;6195&quot;, &quot;6196&quot;, &quot;6197&quot;, &quot;6208&quot;, &quot;6228&quot;, &quot;6229&quot;, &quot;6232&quot;, 
  &quot;6255&quot;, &quot;6268&quot;, &quot;6269&quot;, &quot;6270&quot;, &quot;6275&quot;), class = &quot;factor&quot;), Gender = structure(c(1L, 
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
  1L, 1L, 1L), .Label = c(&quot;Male&quot;, &quot;Female&quot;), class = &quot;factor&quot;), 
      Age = structure(c(2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 
      2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 
      2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L), .Label = c(&quot;Young&quot;, 
      &quot;Old&quot;), class = &quot;factor&quot;), FA = c(0.335363597, 0.275185704, 
      0.381515294, 0.603494346, 0.615962446, 0.534368277, 0.378798842, 
      0.262283027, 0.463445097, 0.479340732, 0.390655279, 0.30846712, 
      0.38545981, 0.402050078, 0.466983199, 0.456424206, 0.402167588, 
      0.295976758, 0.442705005, 0.445807546, 0.607728601, 0.589604795, 
      0.372361958, 0.296392322, 0.311423391, 0.416039616, 0.534221292, 
      0.564736903, 0.411948681, 0.289896786, 0.487889856, 0.559963286, 
      0.577650726, 0.484459132, 0.454060167, 0.280332953), leftright = structure(c(1L, 
      2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
      1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
      2L, 1L, 2L, 1L, 2L), .Label = c(&quot;left&quot;, &quot;right&quot;), class = &quot;factor&quot;), 
      ROI_Coded = structure(c(2L, 2L, 1L, 1L, 3L, 3L, 2L, 2L, 1L, 
      1L, 2L, 2L, 1L, 1L, 3L, 3L, 2L, 2L, 1L, 1L, 3L, 3L, 2L, 2L, 
      1L, 1L, 3L, 3L, 2L, 2L, 1L, 1L, 3L, 3L, 2L, 2L), .Label = c(&quot;LC&quot;, 
      &quot;Noradrenergic&quot;, &quot;FPT&quot;), class = &quot;factor&quot;)), row.names = c(NA, 
  -36L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;), na.action = structure(c(`11` = 11L, 
  `12` = 12L, `54` = 54L, `208` = 208L, `347` = 347L, `348` = 348L, 
  `1089` = 1089L, `1263` = 1263L, `1456` = 1456L), class = &quot;omit&quot;))
  </code></pre>
  <p>Which a subset of that looks like:</p>
  <pre><code>  # A tibble: 36 x 6
     ID    Gender Age      FA leftright ROI_Coded    
     &lt;fct&gt; &lt;fct&gt;  &lt;fct&gt; &lt;dbl&gt; &lt;fct&gt;     &lt;fct&gt;        
   1 5356  Male   Old   0.335 left      Noradrenergic
   2 5356  Male   Old   0.275 right     Noradrenergic
   3 5356  Male   Old   0.382 left      LC           
   4 5356  Male   Old   0.603 right     LC           
   5 5356  Male   Young   0.616 left      FPT          
   6 5356  Male   Young   0.534 right     FPT          
   7 5357  Male   Old   0.379 left      Noradrenergic
   8 5357  Male   Old   0.262 right     Noradrenergic
   9 5357  Male   Old   0.463 left      LC           
  10 5357  Male   Old   0.479 right     LC          
  </code></pre>
  <p>I would like to run a mixed-ANOVA  using the rstatix anova_test function. I have tried running the following:</p>
  <pre><code>res.aov &lt;- rstatix::anova_test(
    data = df2, dv = FA, wid = ID,
    between = c(ROI_Coded,leftright), within = c(Age,Gender)
  )
  </code></pre>
  <p>but repeatedly receive the following output and error:</p>
  <pre><code>The 'wid' column contains duplicate ids across between-subjects variables. Automatic unique id will be created
  Error in `contrasts&lt;-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
    contrasts can be applied only to factors with 2 or more levels
  </code></pre>
  <p>but when I check my data, I have no NAs and at least 2 factors:</p>
  <pre><code>sapply(fctr, nlevels)
  sapply(df2, function(x) sum(is.na(x)))
  
  NAs:
  ID    Gender       Age        FA leftright ROI_Coded 
  0         0         0         0         0         0
  
  Factors:
  ID    Gender       Age leftright ROI_Coded 
  310         2         2         2         3 
  </code></pre>
  <p>I followed the debug contrasts error <a href="https://stackoverflow.com/questions/44200195/how-to-debug-contrasts-can-be-applied-only-to-factors-with-2-or-more-levels-er">here</a> but still receive the errors.</p>
  <p>I'm not sure why or how to continue.</p>