@@ -0,0 +1,1295 @@
+%22%22%22examples for usage of F-test on linear restrictions in OLS%0A%0Alinear restriction is R %5Cbeta = 0%0AR is (nr,nk), beta is (nk,1) (in matrix notation)%0A%22%22%22%0A%0Aimport numpy as np%0Aimport numpy.testing as npt%0Afrom models.datasets.longley.data import load%0Afrom models.regression import OLS%0Afrom models import tools%0A%0Adata = load()%0Adata.exog = tools.add_constant(data.exog)%0Ares = OLS(data.endog, data.exog).fit()%0A%0A# test pairwise equality of some coefficients%0AR = %5B%5B0,1,-1,0,0,0,0%5D,%5B0, 0, 0, 0, 1, -1, 0%5D%5D%0AFtest = res.Fcontrast(R)%0Aprint repr((Ftest.F, Ftest.p_val)) #use repr to get more digits%0A# 9.740461873303655 0.0056052885317360301%0A%0A##Compare to R (after running R_lm.s in the longley folder) looks good.%0A##%0A##%3E library(car)%0A##%3E linear.hypothesis(m1, c(%22GNP = UNEMP%22,%22POP = YEAR%22))%0A##Linear hypothesis test%0A##%0A##Hypothesis:%0A##GNP - UNEMP = 0%0A##POP - YEAR = 0%0A##%0A##Model 1: TOTEMP ~ GNPDEFL + GNP + UNEMP + ARMED + POP + YEAR%0A##Model 2: restricted model%0A##%0A## Res.Df      RSS Df Sum of Sq      F   Pr(%3EF)%0A##1      9   836424%0A##2     11  2646903 -2  -1810479 9.7405 0.005605 **%0A%0A# test all variables have zero effect%0AR = np.eye(7)%5B:-1,:%5D%0AFtest0 = res.Fcontrast(R)%0Aprint repr((Ftest0.F, Ftest0.p_val))%0Aprint '%25r' %25 res.F%0Anpt.assert_almost_equal(res.F, Ftest0.F, decimal=10)%0A# values differ in 11th decimal%0A

add example for Ftest (Fcontrast) for ols