The fit
method of the linear models, discrete models and GLM, take a cov_type
and a cov_kwds
argument for specifying robust covariance matrices. This will be attached to the results instance and used for all inference and statistics reported in the summary table.
Unfortunately, the documentation doesn't really show this yet in an appropriate way.
The auxiliary method that actually selects the sandwiches based on the options shows the options and required arguments:
http://statsmodels.sourceforge.net/devel/generated/statsmodels.regression.linear_model.OLS.fit.html
For example, estimating an OLS model and using HC3
covariance matrices can be done with
model_ols = OLS(...)
result = model_ols.fit(cov_type='HC3')
result.bse
result.t_test(....)
Some sandwiches require additional arguments, for example cluster robust standard errors, can be selected in the following way, assuming mygroups
is an array that contains the groups labels:
results = OLS(...).fit(cov_type='cluster', cov_kwds={'groups': mygroups}
results.bse
...
Some robust covariance matrices make additional assumptions about the data without checking. For example heteroscedasticity and autocorrelation robust standard errors or Newey-West, HAC
, standard errors assume a sequential time series structure. Some panel data robust standard errors also assume stacking of the time series by individuals.
A separate option use_t
is available to specify whether the t and F or the normal and chisquare distributions should be used by default for Wald tests and confidence intervals.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…