title: Use purrr::map to analyze lme4::lmer subjects using agricolae::HSD.test
body: <p>I am having trouble understanding how to use map to apply a function that will analyze the data of individual subjects in my data</p>
  
  <pre><code>library(lme4)
  library(tidyverse)
  library(agricolae)
  </code></pre>
  
  <p>This is the model I start with</p>
  
  <pre><code>fm &lt;- lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy)
  </code></pre>
  
  <p>I can look at the data of individuals:</p>
  
  <pre><code>glimpse(ss &lt;- sleepstudy %&gt;%
      nest(-Subject) %&gt;%
      mutate(fit = map(data, ~ lm(Reaction ~ Days, data = .)),
          results = map(fit, tidy)))
  </code></pre>
  
  <p>I can take an element of ss$fit and apply HSD.test to it</p>
  
  <pre><code>glimpse(hsd &lt;- HSD.test(ss$fit[[1]], trt = 'Days'))
  </code></pre>
  
  <p>But when I try to use map, I get errors. Here are the two forms I used:</p>
  
  <pre><code>rm(ss)
  glimpse(ss &lt;- sleepstudy %&gt;%
      nest(-Subject) %&gt;%
      mutate(fit = map(data, ~ lm(Reaction ~ Days, data = .)),
          results = map(fit, HSD.test(., trt = 'Days'))))
  
  glimpse(ss &lt;- sleepstudy %&gt;%
      nest(-Subject) %&gt;%
      mutate(fit = map(data, ~ lm(Reaction ~ Days, data = .)),
          results = map(fit, HSD.test(fit, trt = 'Days'))))
  </code></pre>