3.1.5 交互作用检验
是否教育对工资的提升在男性中比女性中更多?
上图来自两个不同的拟合。我们需要公式化一个简单的模型来检验总体倾斜的差异。这通过"交互作用"来完成。
In [22]:
result = ols(formula='WAGE ~ EDUCATION + C(SEX) + EDUCATION * C(SEX)', data=data).fit()
print(result.summary())
OLS Regression Results
==============================================================================
Dep. Variable: WAGE R-squared: 0.190
Model: OLS Adj. R-squared: 0.186
Method: Least Squares F-statistic: 41.50
Date: Thu, 19 Nov 2015 Prob (F-statistic): 4.24e-24
Time: 12:06:38 Log-Likelihood: -1575.0
No. Observations: 534 AIC: 3158.
Df Residuals: 530 BIC: 3175.
Df Model: 3
Covariance Type: nonrobust
=========================================================================================
coef std err t P>|t| [95.0% Conf. Int.]
------------- ------------- ------------- ------------- ------------- ------------------------
Intercept 1.1046 1.314 0.841 0.401 -1.476 3.685
C(SEX)[T.1] -4.3704 2.085 -2.096 0.037 -8.466 -0.274
EDUCATION 0.6831 0.099 6.918 0.000 0.489 0.877
EDUCATION:C(SEX)[T.1] 0.1725 0.157 1.098 0.273 -0.136 0.481
==============================================================================
Omnibus: 208.151 Durbin-Watson: 1.863
Prob(Omnibus): 0.000 Jarque-Bera (JB): 1278.081
Skew: 1.587 Prob(JB): 2.94e-278
Kurtosis: 9.883 Cond. No. 170.
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
我们可以得出结论教育对男性的益处大于女性吗?
带回家的信息
- 假设检验和p-值告诉你影响 / 差异的显著性
- 公式 (带有类别变量) 让你可以表达你数据中的丰富联系
- 可视化数据和简单模型拟合很重要!
- 条件化 (添加可以解释所有或部分方差的因素) 在改变交互作用建模方面非常重要。