title: How to conduct linear hypothesis test on regression coefficients with a clustered covariance matrix?
body: <p>I am interested in calculating estimates and standard errors for linear combinations of coefficients after a linear regression in R.  For example, suppose I have the regression and test:</p>
  
  <pre><code>data(mtcars)
  library(multcomp)
  lm1 &lt;- lm(mpg ~ cyl + hp, data = mtcars)
  summary(glht(lm1, linfct = 'cyl + hp = 0'))
  </code></pre>
  
  <p>This will estimate the value of the sum of the coefficients on <code>cyl</code> and <code>hp</code>, and provide the standard error based on the covariance matrix produced by <code>lm</code>.</p>
  
  <p>But, suppose I want to cluster my standard errors, on a third variable:</p>
  
  <pre><code>data(mtcars)
  library(multcomp)
  library(lmtest)
  library(multiwayvcov)
  lm1 &lt;- lm(mpg ~ cyl + hp, data = mtcars)
  vcv &lt;- cluster.vcov(lm1, cluster = mtcars$am)
  ct1 &lt;- coeftest(lm1,vcov. = vcv)
  </code></pre>
  
  <p><code>ct1</code> contains the SEs for my clustering by <code>am</code>.  However, if I try to use the <code>ct1</code> object in <code>glht</code>, you get an error saying </p>
  
  <blockquote>
    <p>Error in modelparm.default(model, ...) : 
      no ‘coef’ method for ‘model’ found!</p>
  </blockquote>
  
  <p>Any advice on how to do the linear hypothesis with the clustered variance covariance matrix?</p>
  
  <p>Thanks!</p>