linearmodels.iv.absorbing.AbsorbingLS.fit¶
-
AbsorbingLS.fit(*, cov_type: str =
'robust', debiased: bool =False, method: str ='auto', absorb_options: dict[str, bool | float | str | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | dict[str, Any] | None] | None =None, use_cache: bool =True, lsmr_options: dict[str, float | bool] | None =None, **cov_config: Any) AbsorbingLSResults[source]¶ Estimate model parameters.
- Parameters:¶
- cov_type: str =
'robust'¶ Name of covariance estimator to use. The default is “robust”. The names are not case sensitive. Supported covariance estimators are:
”unadjusted”, “homoskedastic”, “homo”, “homoskedasticcovariance” - Classic homoskedastic inference
”robust”, “heteroskedastic”, “hccm”, “heteroskedasticcovariance” - Heteroskedasticity robust inference
”kernel”, “kernelcovariance” - Heteroskedasticity and autocorrelation robust inference
”clustered”, “one-way”, “onewayclusteredcovariance” - Cluster dependent inference, which is heteroskedasticity robust. It is one-way unless
clustershas two columns.
- debiased: bool =
False¶ Flag indicating whether to debias the covariance estimator using a degree of freedom adjustment. The default is False.
- method: str =
'auto'¶ The algorithm that absorbs the variables. The names are not case sensitive, and a ValueError is raised for any other value. One of:
”auto” - (Default). Use HDFE when applicable and fallback to LSMR.
”lsmr” - Force LSMR.
”hdfe” - Force HDFE. Raises RuntimeError if the model contains continuous variables or continuous-binary interactions to absorb or if the model is weighted.
- absorb_options: dict[str, bool | float | str | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | dict[str, Any] | None] | None =
None¶ Dictionary of options to pass to the absorber. Passed to either scipy.sparse.linalg.lsmr or pyhdfe.create depending on the method used to absorb the absorbed regressors. The options have to be those of the algorithm that is used, which is HDFE if method is “auto” and the model can be absorbed using it. A ValueError is raised for options of LSMR if the variables are absorbed using HDFE, and for options of pyhdfe.create if they are absorbed using LSMR.
- use_cache: bool =
True¶ Flag indicating whether the variables, once purged from the absorbed variables and interactions, should be stored in the cache, and retrieved if available. Cache can dramatically speed up re-fitting large models when the set of absorbed variables and interactions are identical. The default is True.
- lsmr_options: dict[str, float | bool] | None =
None¶ Options to pass to scipy.sparse.linalg.lsmr. If they are not empty, method “auto” absorbs the variables using LSMR, and method “hdfe” raises a ValueError.
Deprecated since version 4.17: Use absorb_options with method=”lsmr” to pass options.
lsmr_optionswill be removed in linearmodels 8.0.- **cov_config: Any¶
Additional parameters to pass to the covariance estimator. The keys that are used depend on
cov_type. “unadjusted” and “robust” do not use any. “kernel” useskernel(str), the name of the kernel, which is “bartlett” if it is not provided, andbandwidth(int), which is selected from the data if it is not provided. The names of the kernels are not case sensitive. “clustered” usesclusters(array_like), the cluster assignment of each observation, with one or two columns. The keyscenter,kappaandextra_dfare accepted and ignored: the absorbed effects set the degrees of freedom. SeeHomoskedasticCovariance,HeteroskedasticCovariance,KernelCovarianceandClusteredCovariancefor the details.
- cov_type: str =
- Returns:¶
Results container.
- Return type:¶
- Raises:¶
ValueError – If
methodis not supported, ifabsorb_optionscontains options of the algorithm that is not used, iflsmr_optionsis used withabsorb_optionsor withmethod="hdfe", if all columns inexogare absorbed anddrop_absorbedis True, ifdebiasedis True and the model has no degrees of freedom left, or if the labels ofclustersdo not match the labels of the other inputs. A key ofcov_configthat the covariance estimator thatcov_typeselects does not accept also raises it. The message names the key and lists the accepted keys. This is checked before the model is estimated. Releases before 7.1 raised theTypeErrorof the constructor of the covariance estimator.RuntimeError – If
methodis “hdfe” and the model cannot be absorbed using HDFE.Exception – An
AbsorbingEffectError, which is defined inlinearmodels.panel.utility, if a variable inexogis absorbed by the effects anddrop_absorbedis False.UnknownOptionError – If
cov_typeorkernelis not supported. It is both aKeyErrorand aValueError.
- Warns:¶
AbsorbingEffectWarning – If a variable in
exogis absorbed by the effects anddrop_absorbedis True. The variable is dropped.FutureWarning – If
lsmr_optionsis used.
See also
linearmodels.iv.covariance.HomoskedasticCovarianceHomoskedastic covariance.
linearmodels.iv.covariance.HeteroskedasticCovarianceHeteroskedasticity robust covariance.
linearmodels.iv.covariance.KernelCovarianceKernel (HAC) covariance.
linearmodels.iv.covariance.ClusteredCovarianceClustered covariance.
Notes
Additional covariance parameters depend on specific covariance used. See the docstring of the specific covariance estimator for a list of supported options. Defaults are used if no covariance configuration is provided.
Observations with a missing value in
dependent,exog,weights,absorborinteractionsare dropped when the model is created. Whencov_typeis “clustered”,clustersmust have one row for each of the remaining observations, so the rows ofclustersthat belong to dropped observations must be dropped too.If use_cache is True, then variables are hashed based on their contents using either a 64-bit value (if xxhash is installed) or a 256-bit value. This allows variables to be reused in different models if the set of absorbing variables and interactions is held constant. The options used to absorb the variables are part of what identifies them.
If
debiasedis True, the covariance estimator is adjusted for the degrees of freedom that the model uses: the k regressors inexogthat are estimated and the d degrees of freedom of the absorbed terms. They are the dummy variables of the effects, with one less ifexoghas a constant and one less for each effect after the first, the absorbed continuous variables and the interactions, which isdf_absorbed. The unadjusted, robust and kernel covariances are multiplied by n / (n - k - d), and the clustered covariance by g (n - 1) / ((g - 1) (n - k - d)) where g is the number of clusters. The result is that of the regression of the dependent variable onexogand the dummy variables of the effects. It is also that ofPanelOLS(debiased=True)with the same effects, usinggroup_debias=Truefor the clustered covariance. The exception is a clustered covariance when there is a single categorical effect and each of its categories is in one cluster of every cluster variable: its degrees of freedom are not counted, since the effect is nested in the clusters, as inPanelOLSand Stata. UnlikePanelOLS, nothing is adjusted ifdebiasedis False. The t and F distributions of the results usedf_residwhatever the covariance estimator. AValueErroris raised ifdebiasedis True and the model has no degrees of freedom left.The variables are absorbed when fit is called for the first time. A later call uses the same absorbed variables if
method,absorb_optionsanduse_cachehave the same values, so that changing only the covariance estimator is fast. If any of them differs, the variables are absorbed again using the new values.