hasconst在python statsmodels中有什么作用?

时间:2019-08-08 02:37:48

标签: python statsmodels

我对statsmodels“ hasconst”非常困惑-根据文档:

hasconst:无或为布尔     指示RHS是否包括用户提供的常数。如果是真的,     不检查常量,并且k_constant设置为1,并且所有     结果统计量的计算就好像存在一个常量一样。如果     False,不检查常量,并且k_constant设置为0。

但是无论我将其设置为True,False,None等...,我都看不出计算参数的差异。 hasconst在做什么?

import numpy as np
import statsmodels.api as sm


np.random.seed(10)
X1 = np.random.randn(10000)
X2 = np.random.randn(10000)
Y = X1*2 + X2*3 + 500
X = np.stack([X1,X2], axis=1)
#X = sm.add_constant(X)
model = sm.OLS(Y, X, hasconst=False).fit()
model.params

>>array([ 4.57554805, -0.11879962])

np.random.seed(10)
X1 = np.random.randn(10000)
X2 = np.random.randn(10000)
Y = X1*2 + X2*3 + 500
X = np.stack([X1,X2], axis=1)
#X = sm.add_constant(X)
model = sm.OLS(Y, X, hasconst=True).fit()
model.params

>>array([ 4.57554805, -0.11879962])


np.random.seed(10)
X1 = np.random.randn(10000)
X2 = np.random.randn(10000)
Y = X1*2 + X2*3 + 500
X = np.stack([X1,X2], axis=1)
X = sm.add_constant(X)
model = sm.OLS(Y, X, hasconst=True).fit()
model.params

>> array([500.,   2.,   3.])



np.random.seed(10)
X1 = np.random.randn(10000)
X2 = np.random.randn(10000)
Y = X1*2 + X2*3 + 500
X = np.stack([X1,X2], axis=1)
X = sm.add_constant(X)
model = sm.OLS(Y, X, hasconst=False).fit()
model.params
>> array([500.,   2.,   3.])

0 个答案:

没有答案