title: How to add a covariate to a between-within design MANCOVA with R?
body: <hr />
  <p>I want to run a between-within design MANCOVA with R, with two dependent variables (Planned and Unplanned), two between-subject variables (Genre [Male, Female] and Urb [Yes, No]), one within-subject variable (Period [Before, During]), and one covariate (BMI).</p>
  <p>Here is what I've done (see here for similar calculation: <a href="https://stats.stackexchange.com/questions/183441/correct-way-to-perform-a-one-way-within-subjects-manova-in-r">https://stats.stackexchange.com/questions/183441/correct-way-to-perform-a-one-way-within-subjects-manova-in-r</a>):</p>
  <pre><code># Create dummy data
  data &lt;- data.frame(Quest_before_planned = sample(1:100, 10),
                     Quest_during_planned = sample(1:100, 10),
                     Quest_before_unplanned = sample(1:100, 10),
                     Quest_during_unplanned = sample(1:100, 10),
                     Genre = sample(rep(c(&quot;Male&quot;, &quot;Female&quot;), each = 5)),
                     Urb = sample(rep(c(&quot;Yes&quot;, &quot;No&quot;), each = 5)),
                     BMI = sample(1:100, 10))
  
  # Define the within-subjects factor
  period &lt;- as.factor(rep(c('before','during'), each = 2))
  idata &lt;- data.frame(period)
  
  # Create the data structure for the linear model
  data.model &lt;- with(data, cbind(Quest_before_planned, Quest_during_planned,
                                 Quest_before_unplanned, Quest_during_unplanned))
  
  # Build the multivariate-linear model
  mod.mlm &lt;- lm(data.model ~ Genre * Urb, data = data_total)
  
  # Run the MANOVA
  mav.blpaq &lt;- Anova(mod.mlm, idata = idata, idesign = ~ period, type = 2)
  print(mav.blpaq)
  </code></pre>
  <p>Thus, the between-within design MANOVA here works well. However, I failed to add a covariate (i.e., BMI) to this model. Do you know how can I achieve this?</p>
  <hr />
  <p>N.B.: I also tried using the (great) <code>mancova()</code> function , which include a covariate parameter; but with this function, I do not know how to specify that Period is a within-subject variable...</p>
  <pre><code>blpaq_macov &lt;- mancova(data_tidy,
                         deps = c(&quot;Quest_planned&quot;, &quot;Quest_unplanned&quot;),
                         factors = c(&quot;Genre&quot;, &quot;Period&quot;, &quot;Urb&quot;),
                         covs = &quot;BMI&quot;,
                         multivar = &quot;pillai&quot;)
  </code></pre>