title: Replacing Standard Errors in a Reg Model in R
body: <p>I am in search of a way to directly replace the standard errors in a regression model with my own standard errors in order to use the robust model in another R package that does not come with its own robust option and can only be fed particular types of models and not coeftest formats. </p>
  
  <p>Let's say I have a linear model:</p>
  
  <pre><code>model &lt;- lm(data=dat, Y ~ X1 + X2 + X3)
  </code></pre>
  
  <p>I then want robust standard errors:</p>
  
  <pre><code>robust &lt;- coeftest(model, vcov=sandwich)
  </code></pre>
  
  <p>Next, I need to use this model in a specific package that cannot be fed a coeftest and does not have its own robust standard errors option. I would like to replace the original model's standard errors (and, for that matter, p-values, t-statistics, etc.) prior to feeding it into the package so that they are accounted for. </p>
  
  <p>To access the standard errors in the <em>original model</em>, I use: </p>
  
  <pre><code>summary(model)$coefficients[,2]
  </code></pre>
  
  <p>To extract the standard errors from the <em>coeftest</em>, I use:</p>
  
  <pre><code>coeftest.se &lt;- robust[, 2]
  </code></pre>
  
  <p>The following method, however, returns an error when trying to replace the model's standard errors because it is treating "summary" itself as a command:</p>
  
  <pre><code>summary(model)$coefficients[,2] &lt;- coeftest.se
  
  
  Error in summary(M3)$coefficients[, 2] &lt;- seM3 : could not find function "summary&lt;-"
  </code></pre>
  
  <p><strong>The Specifics</strong></p>
  
  <p>I am trying to run mediation analysis with the Mediation R package. The package will do one way clustered standard errors with the "mediate" function, but I would like two way clustered standard errors. </p>
  
  <p>To get two way clustered standard errors, I am using Mahmood Arai's mclx function (code can be found <a href="http://www.ne.su.se/polopoly_fs/1.216115.1426234213!/menu/standard/file/clustering1.pdf" rel="noreferrer">here</a> (p. 4). </p>
  
  <p>My idea is to feed the package's mediate function with models that already report the correct standard errors. According the documentation, the mediation package accepts the following classes of models: lm, polr, bayespolr, glm, bayesglm, gam, rq, survreg, and merMod.</p>