# How to test whether $\beta_1= \beta_3 = 0.5$ using R (without using offset function)?

I want to know if I am correctly implementing the answer given by Michael Chirico here.

The dataset can obtained using the following code in R:

data = fread(paste0("http://www1.aucegypt.edu/faculty/hadi/RABE5/Data5/", "P060.txt"))


I want to test $$H_0: \beta_1 = \beta_3 =0.5$$ using the model $$Y = \beta_0 + \beta_1 X_1 + \beta_3 X_3 + e.$$

In the answer from the link above, we can obtain an equivalent null hypothesis and a new model,

$$H_0: \alpha_1 = \alpha_3 = 0,$$

where the new model is

\begin{align*} Y - 0.5(X_1 + X_3) &= \beta_0 + (\beta_1 - 0.5)X_1 + (\beta_3 - 0.5)X_3 + e \\ &= \alpha_0 + \alpha_1 X_1 + \alpha_3 X_3 + e \end{align*}

With the new hypothesis and model, this becomes more familiar to me. I can use the partial F-test to determine whether we reject the null hypothesis or not.

In R I do the following:

m.null = lm(Y - 0.5*(X1+X3) ~ 1,     data=supdata)
m.alt  = lm(Y - 0.5*(X1+X3) ~ X1+X3, data=supdata)
anova(m.null, m.alt)


I can obtain the F-statistics and use its p-value to make a decision but I would first like to make sure that my implementation is correct.

• Yes, it is correct. – Gordon Smyth Mar 26 '18 at 2:48
• Lets say model null is likely to be correct. How you gonna interpret that in terms of beta1=beta3=0.5 ? – Jak Jac Mar 26 '18 at 17:53
• Note that for a general case it's also a good idea to use Likelihood Ratio test instead of F test lmtest::lrtest(m.null, m.alt) due to less restrictions for the asymptotics to hold. Although, for OLS, as in your case, both tests are equivalent. – Nutle May 14 '19 at 23:07

First Create the model

data = fread(paste0("http://www1.aucegypt.edu/faculty/hadi/RABE5/Data5/", "P060.txt"))
model <- lm(data = data, Y ~ X1 + X3)


Then you can use the following code:

library(car)
linearHypothesis(model, c("X1=X3", "X1=0.5"))


You will get the same output with less code and hassle.