Search code examples
rlinear-regression

F test for β1=β2 in R


If my model looks like this, Y=β0+β1X1+β2X2+β3X3+β4X4, and I want to perform an F test (5%) in R for β1=β2, how do I do it? The only tutorials I can find online deal with β1=β2=0, but that's not what I'm looking for here.


Solution

  • Here's an example in R testing whether the coefficient for vs is the same as the coefficient for am:

    data(mtcars)
    mod <- lm(mpg ~ hp + disp + vs + am, data=mtcars)
    library(car)
    linearHypothesis(mod, "vs=am")
    # Linear hypothesis test
    # 
    # Hypothesis:
    #   vs - am = 0
    # 
    # Model 1: restricted model
    # Model 2: mpg ~ hp + disp + vs + am
    # 
    # Res.Df    RSS Df Sum of Sq      F Pr(>F)
    # 1     28 227.07                           
    # 2     27 213.52  1    13.547 1.7131 0.2016