title: Removing outliers from linear regression when using multiple models
body: <p>I would like to rerun my multiple linear regression analyses having removed influential observations/outliers to determine their effect. My data has approximately 1000 observations of 30 variables (5 predictors, 25 outcomes).</p>
  
  <pre><code>df &lt;- data.frame(replicate(30, sample(0:1000, 1000, rep = TRUE)))
  </code></pre>
  
  <p>I perform multiple linear regression for each of the 25 outcome variables:</p>
  
  <pre><code>library(tidyverse)
  
  reg &lt;- df %&gt;%
    gather(outcome_name, outcome_value, -(X1 : X5)) %&gt;%
    group_by(outcome_name) %&gt;%
    nest() %&gt;%
    mutate(model = map(data, ~lm(outcome_value ~ X1 + X2 + X3 + X4 + X5, data 
    =.)))
  </code></pre>
  
  <p>And then I can subsequently extract the statistics of interest:</p>
  
  <pre><code>stats &lt;- reg %&gt;%
    mutate(glance = map(model, broom::glance), 
           tidy = map(model, broom::tidy, conf.int = TRUE)
    )
  </code></pre>
  
  <p>I would like to rerun the above but having removed the outliers either identified, for example, by being > 2 standard deviations above mean, or by identifying them with something like Cook's distance. However, I can't figure out how to exclude the outliers in my code so that each regression model iterates appropriately. </p>
  
  <p>I have tried filtering observations > 2 SD above mean for each outcome variable prior to performing the regression, but I then lost those observations for all 25 outcome regression models, as opposed to the single outcome model for which that observation is an outlier. Any suggestions appreciated.</p>