1
"""examples for usage of F-test on linear restrictions in OLS
3
linear restriction is R \beta = 0
4
R is (nr,nk), beta is (nk,1) (in matrix notation)
8
import numpy.testing as npt
9
from models.datasets.longley.data import load
10
from models.regression import OLS
11
from models import tools
14
data.exog = tools.add_constant(data.exog)
15
res = OLS(data.endog, data.exog).fit()
17
# test pairwise equality of some coefficients
18
R = [[0,1,-1,0,0,0,0],[0, 0, 0, 0, 1, -1, 0]]
19
Ftest = res.Fcontrast(R)
20
print repr((Ftest.F, Ftest.p_val)) #use repr to get more digits
21
# 9.740461873303655 0.0056052885317360301
23
##Compare to R (after running R_lm.s in the longley folder) looks good.
26
##> linear.hypothesis(m1, c("GNP = UNEMP","POP = YEAR"))
27
##Linear hypothesis test
33
##Model 1: TOTEMP ~ GNPDEFL + GNP + UNEMP + ARMED + POP + YEAR
34
##Model 2: restricted model
36
## Res.Df RSS Df Sum of Sq F Pr(>F)
38
##2 11 2646903 -2 -1810479 9.7405 0.005605 **
40
# test all variables have zero effect
42
Ftest0 = res.Fcontrast(R)
43
print repr((Ftest0.F, Ftest0.p_val))
45
npt.assert_almost_equal(res.F, Ftest0.F, decimal=10)
46
# values differ in 11th decimal
b'\\ No newline at end of file'