更多详情可以查看help page for f test on statsmodels results。
例如你的数据是这样的(我只使用了 5 个变量):
import numpy as np
import pandas as pd
import statsmodels.api as sm
np.random.seed(999)
data = pd.DataFrame(np.random.uniform(0,1,(50,6)),
columns=['x1','x2','x3','x4','x5','y'])
我们可以拟合回归,结果如下:
results = sm.OLS(endog= data['y'],exog=sm.add_constant(data.iloc[:,:5])).fit()
results.summary()
coef std err t P>|t| [0.025 0.975]
const 0.7432 0.201 3.700 0.001 0.338 1.148
x1 -0.0345 0.147 -0.235 0.816 -0.331 0.262
x2 -0.1758 0.151 -1.165 0.250 -0.480 0.128
x3 -0.1472 0.150 -0.982 0.331 -0.449 0.155
x4 -0.2735 0.144 -1.905 0.063 -0.563 0.016
x5 0.1143 0.135 0.845 0.403 -0.158 0.387
建立假设,在这种情况下x3和x4为零,然后进行测试:
hypotheses = '(x3 = 0), (x4 = 0)'
f_test = results.f_test(hypotheses)
print(f_test)
<F test: F=array([[2.64119819]]), p=0.08255414803527926, df_denom=44, df_num=2>