Матрицы форм HC4, HC4m и HC5, точно такие же, как и в R здесь: https://www.rdocumentation.org/packages/sandwich/versions/3.0-2/topics/vcovHC
Сами коды получения ковариационных матриц можно посмотреть здесь: https://github.com/dogfew/statsmodels_HC_cov/blob/main/statsmodels_HC_cov/cov.py
Тесты писать мне лень.
git clone https://github.com/dogfew/statsmodels_HC_cov
cd statsmodels_HC_cov
python main.py
Enter.
pip uninstall statsmodels-hc-cov
Сначала необходимо подготовить модель типа OLS из statsmodels.api, и зафитить её.
>>> from sklearn.datasets import make_regression
>>> X, y = make_regression(n_features=4, random_state=442, bias=9.2, noise=50)
>>> from statsmodels.api import OLS, add_constant
>>> model = OLS(y, add_constant(X)).fit()
>>> from statsmodels_HC_cov import cov_hc5, cov_hc4, cov_hc4m, vcov_hc, ttest
>>> cov_hc5(model)
array([[29.52750556, 2.45112295, 7.72272458, -0.15248637, 4.38382457],
[ 2.45112295, 21.79997686, 6.49405244, 2.07311453, -2.87778095],
[ 7.72272458, 6.49405244, 49.04041299, 5.75572217, -3.50458931],
[-0.15248637, 2.07311453, 5.75572217, 26.00612708, -2.06287357],
[ 4.38382457, -2.87778095, -3.50458931, -2.06287357, 20.6567492 ]])
>>> vcov_hc(model, cov_type='hc5')
array([[29.52750556, 2.45112295, 7.72272458, -0.15248637, 4.38382457],
[ 2.45112295, 21.79997686, 6.49405244, 2.07311453, -2.87778095],
[ 7.72272458, 6.49405244, 49.04041299, 5.75572217, -3.50458931],
[-0.15248637, 2.07311453, 5.75572217, 26.00612708, -2.06287357],
[ 4.38382457, -2.87778095, -3.50458931, -2.06287357, 20.6567492 ]])
>>> test = ttest(model, cov_type='hc5')
>>> test
coefs std err t P >|t|
X0 11.7997 5.4339 2.1715 0.0323
X1 56.4308 4.6690 12.0862 0.0000
X2 80.1752 7.0029 11.4489 0.0000
X3 63.9853 5.0996 12.5471 0.0000
X4 5.4531 4.5450 1.1998 0.2330
>>> test.coefs
array([11.79973021, 56.43078829, 80.17520362, 63.98529449, 5.45309485])
>>> test.se
array([5.43392175, 4.66904453, 7.00288605, 5.09962029, 4.54496966])
>>> test.tvalues
array([ 2.17149432, 12.08615336, 11.44888023, 12.54707035, 1.19980886])
>>> test.pvalues
array([3.22586682e-02, 2.86977490e-21, 6.80700155e-20, 2.96554697e-22,
2.33048476e-01])
>>> test['X0']['t']
2.1714943190800806
>>> test['t']
X0 2.171494
X1 12.086153
X2 11.448880
X3 12.547070
X4 1.199809
Name: t, dtype: float64
У меня сгорело, что я нигде в питоне это не нашёл. Впрочем, это никому и не нужно, кроме студентов.