library(“lmtest”) # for coeftest()
library(“MASS”) # for Boston housing data
data(“Boston”) # ?Boston; names(Boston)
# focusing here on a small sample case (n=20):
Boston_small <- Boston[1:20,]
lm_obj <- lm(medv ~ ptratio + lstat + nox + crim, data = Boston_small)
round(coeftest(lm_obj), 2)
#> t test of coefficients:
#>
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 112.59 39.86 2.82 0.01 **
#> ptratio -0.92 1.00 -0.92 0.37
#> lstat -0.47 0.18 -2.57 0.02 *
#> nox -134.72 53.73 -2.51 0.02 *
#> crim 4.99 8.65 0.58 0.57
#> —
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
library(“car”)
linearHypothesis(lm_obj, c(“lstat=0”, “nox=0”))
#> Linear hypothesis test
#>
#> Hypothesis:
#> lstat = 0
#> nox = 0
#>
#> Model 1: restricted model
#> Model 2: medv ~ ptratio + lstat + nox + crim
#>
#> Res.Df RSS Df Sum of Sq F Pr(>F)
#> 1 17 344.27
#> 2 15 190.40 2 153.88 6.0614 0.01177 *
#> —
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
install.packages(“sandwich”)
install.packages(“lmtest”)
install.packages(“car”)
install.packages(“AER”)
library(“sandwich”)
library(“lmtest”)
library(“car”)
library(“AER”)