Question

I have a linear model generated using lm. I use the coeftest function in the package lmtest go test a hypothesis with my desired vcov from the sandwich package. The default null hypothesis is beta = 0. What if I want to test beta = 1, for example. I know I can simply take the estimated coefficient, subtract 1 and divide by the provided standard error to get the t-stat for my hypothesis. However, there must be functionality for this already in R. What is the right way to do this?

MWE:

require(lmtest)
require(sandwich)
set.seed(123)
x = 1:10
y = x + rnorm(10)
mdl = lm(y ~ x)
z = coeftest(mdl, df=Inf, vcov=NeweyWest)
b = z[2,1]
se = z[2,2]
mytstat = (b-1)/se
print(mytstat)
Was it helpful?

Solution

the formally correct way to do this:

require(multcomp)
zed = glht(model=mdl, linfct=matrix(c(0,1), nrow=1, ncol=2), rhs=1, alternative="two.sided", vcov.=NeweyWest)
summary(zed)

OTHER TIPS

Use an offset of -1*x

mdl<-lm(y~x)
mdl2 <- lm(y ~ x-offset(x) )

> mdl

Call:
lm(formula = y ~ x)

Coefficients:
(Intercept)            x  
     0.5255       0.9180  

> mdl2

Call:
lm(formula = y ~ x - offset(x))

Coefficients:
(Intercept)            x  
    0.52547     -0.08197 

You can look at summary(mdl2) to see the p-value (and it is the same as in mdl.

As far as I know, there is no default function to test the model coefficients against arbitrary value (1 in your case). There is the offset trick presented in the other answer, but it's not that straightforward (and always be careful with such model modifications). So, your expression (b-1)/se is actually a good way to do it.

I have two notes on your code:

  1. You can use summary(mdl) to get the t-test for 0.
  2. You are using lmtest with covariance structure (which will change the t-test values), but your original lm model doesn't have it. Perhaps this could be a problem? Perhaps you should use glm and specify the correlation structure from the start.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top