How to test linear restriction with both intercept and slope

I have estimated the model

$$y = \beta_{0} + \beta_{1}x + u$$

I want to test the restriction that $$\beta_{0} = 3$$ and that $$\beta_{1} = -2$$. after setting both betas to their hypothesized values and rearranging, I get the equation:

$$z = u$$ where $$z = y + 2x -3$$

now I am lost as to how to actually run this regression because there are no independent variable and no intercept as well. if the value for the intercept was not restricted then i would simply define a new variable as $$y + 2x$$ and just compute it's ssr and use it to compute an F-statistics.

• This is a one-liner in R: anova(lm(y ~ x), {y <- y - (3 + -2*x); lm(y ~ 0)}). There's a trick involved: you have to fool anova into believing you used the same response variable in both models--you can't give them different names (like y and y.1, say).
– whuber
Commented Jan 29, 2022 at 20:00
• @whuber Thanks, This seems to give me that answer I need. correct me if I'm wrong but the ssr for lm(y~0) is just the sum of squares of the new y right? what does lm(y~0) actually compute? Commented Jan 30, 2022 at 8:02
• lm(y ~ 0) basically asks lm to treat y as if it were the residuals (which it is, relative to your null model) and perform its standard calculations. It doesn't do any fitting (which it cheerfully tells you when you apply print or summary to its output).
– whuber
Commented Jan 30, 2022 at 15:48
• Got it, Thank you very much. Commented Jan 31, 2022 at 4:57

You can compute the sum of squared errors (or the likelihood in, say, a logistic regression case) and then conduct an $$F$$-test. You'll probably have to do it manually.
$$F = \frac{ \frac{SS_{resid,restricted}-SS_{resid,full}}{df_{resid,restricted}-df_{resid,full}}} {\frac{SS_{resid,full}}{df_{resid,full}}}$$