I'd like to test the value of a $\beta$ parameter estimated on a linear model. To be specific I want to test $H_0: \beta_1 = -3$ but I'm not sure if the procedure I used in R is correct.
This is the code I used:
attach(mtcars)
require(boot)
set.seed(5)
# Define the linear model
fit = lm(mpg ~ hp)
sum = summary(fit)
sum
# Define the null hypothesis for beta1
H0 = 1
Then, I calculate the test statistic with
$$T_{oss} = \frac{\hat{\beta_1} -\beta_1}{\sqrt{\hat{V}(\hat{\beta_1})}}$$
toss = (coefficients(fit)[2]-H0)/sum$coefficients[4]; toss
pval = 2*(1-pt(toss, length(hp)-2)); pval
# bootstrap procedure
e = rstandard(fit)
fitted = fit$fitted.values
toss.boot <- function(x, idx){
y = fitted + e[idx]
fit = lm(y~hp)
sum = summary(fit)
toss1 = (coefficients(fit)[2]-H0)/sum$coefficients[4]
return (toss1)
}
out.boot = boot(mtcars, statistic = toss.boot, R=1000)
# pvalue as proportion of values more extreme than the one observed
pval = sum(out.boot$t>toss)/length(out.boot$t)
pval
I'm pretty sure there is something wrong but I would like to get your feedback and hopefully suggestions on other/better approaches.