本文整理汇总了Python中statsmodels.regression.linear_model.OLS.compare_lm_test方法的典型用法代码示例。如果您正苦于以下问题:Python OLS.compare_lm_test方法的具体用法?Python OLS.compare_lm_test怎么用?Python OLS.compare_lm_test使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statsmodels.regression.linear_model.OLS
的用法示例。
在下文中一共展示了OLS.compare_lm_test方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_score_test_OLS
# 需要导入模块: from statsmodels.regression.linear_model import OLS [as 别名]
# 或者: from statsmodels.regression.linear_model.OLS import compare_lm_test [as 别名]
def test_score_test_OLS():
# nicer example than Longley
from statsmodels.regression.linear_model import OLS
np.random.seed(5)
nobs = 100
sige = 0.5
x = np.random.uniform(0, 1, size=(nobs, 5))
x[:, 0] = 1
beta = 1. / np.arange(1., x.shape[1] + 1)
y = x.dot(beta) + sige * np.random.randn(nobs)
res_ols = OLS(y, x).fit()
res_olsc = OLS(y, x[:, :-2]).fit()
co = res_ols.compare_lm_test(res_olsc, demean=False)
res_glm = GLM(y, x[:, :-2], family=sm.families.Gaussian()).fit()
co2 = res_glm.model.score_test(res_glm.params, exog_extra=x[:, -2:])
# difference in df_resid versus nobs in scale see #1786
assert_allclose(co[0] * 97 / 100., co2[0], rtol=1e-13)
示例2: res_opg
# 需要导入模块: from statsmodels.regression.linear_model import OLS [as 别名]
# 或者: from statsmodels.regression.linear_model.OLS import compare_lm_test [as 别名]
def res_opg(self):
res_ols = self.res_ols
nobs = self.nobs
moms = self.moms
moms_obs = self.moms_obs
covm = self.covm
moms_deriv = self.moms_deriv
weights = self.weights
L = self.L
x = self.exog_full
res_ols2_hc0 = OLS(res_ols.model.endog, x).fit(cov_type='HC0')
res_all = []
# auxiliary regression
ones = np.ones(nobs)
stat = nobs * OLS(ones, moms_obs).fit().rsquared
res_all.append(('ols R2', stat))
tres = res_ols2_hc0.compare_lm_test(res_ols, demean=False)
res_all.append(('comp_lm uc', tres))
tres = CMTNewey(moms, covm, covm[:,:-2], weights, L).chisquare
res_all.append(('Newey', tres))
tres = CMTTauchen(moms[:-2], covm[:-2, :-2], moms[-2:], covm[-2:, :-2],
covm).chisquare
res_all.append(('Tauchen', tres))
tres = diao.lm_robust_subset(moms[-2:], 2, covm, covm)
res_all.append(('score subset QMLE', tres))
tres = diao.lm_robust(moms, np.eye(moms.shape[0])[-2:],
np.linalg.inv(covm), covm, cov_params=None)
res_all.append(('scoreB QMLE', tres))
tres = diao.lm_robust(moms, np.eye(moms.shape[0])[-2:],
np.linalg.inv(covm), None,
cov_params=np.linalg.inv(covm))
res_all.append(('scoreV QMLE', tres))
return res_all