def fit( self, *, cov_type: str = "robust", debiased: bool = False, method: str = "auto", absorb_options: Optional[Dict[str, Union[bool, str, ArrayLike, None, Dict[str, Any]]]] = None, use_cache: bool = True, lsmr_options: Optional[Dict[str, Union[float, bool]]] = None, **cov_config: Any, ) -> AbsorbingLSResults: """ Estimate model parameters Parameters ---------- cov_type : str, optional Name of covariance estimator to use. Supported covariance estimators are: * 'unadjusted', 'homoskedastic' - Classic homoskedastic inference * 'robust', 'heteroskedastic' - Heteroskedasticity robust inference * 'kernel' - Heteroskedasticity and autocorrelation robust inference * 'cluster' - One-way cluster dependent inference. Heteroskedasticity robust debiased : bool, optional Flag indicating whether to debiased the covariance estimator using a degree of freedom adjustment. method : str, optional 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, optional 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. use_cache : bool 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. lsmr_options: dict Options to ass to scipy.sparse.linalg.lsmr. .. deprecated:: 4.17 Use absorb_options to pass options **cov_config Additional parameters to pass to covariance estimator. The list of optional parameters differ according to ``cov_type``. See the documentation of the alternative covariance estimators for the complete list of available commands. Returns ------- AbsorbingLSResults Results container Notes ----- Additional covariance parameters depend on specific covariance used. The see the docstring of specific covariance estimator for a list of supported options. Defaults are used if no covariance configuration is provided. 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. See also -------- linearmodels.iv.covariance.HomoskedasticCovariance linearmodels.iv.covariance.HeteroskedasticCovariance linearmodels.iv.covariance.KernelCovariance linearmodels.iv.covariance.ClusteredCovariance """ if lsmr_options is not None: if absorb_options is not None: raise ValueError( "absorb_options cannot be used with lsmr_options") warnings.warn("lsmr_options is deprecated. Use absorb_options.", FutureWarning) absorb_options = {k: v for k, v in lsmr_options.items()} if self._absorbed_dependent is None: self._first_time_fit(use_cache, absorb_options, method) exog_resid = self.absorbed_exog.to_numpy() dep_resid = self.absorbed_dependent.to_numpy() if self._exog.shape[1] == 0: params = empty((0, 1)) else: params = lstsq(exog_resid, dep_resid, rcond=None)[0] self._num_params += exog_resid.shape[1] cov_estimator = COVARIANCE_ESTIMATORS[cov_type] cov_config["debiased"] = debiased cov_config["kappa"] = 0.0 cov_config_copy = {k: v for k, v in cov_config.items()} if "center" in cov_config_copy: del cov_config_copy["center"] cov_estimator_inst = cov_estimator(exog_resid, dep_resid, exog_resid, params, **cov_config_copy) results = {"kappa": 0.0, "liml_kappa": 0.0} pe = self._post_estimation(params, cov_estimator_inst, cov_type) results.update(pe) results["df_model"] = self._num_params return AbsorbingLSResults(results, self)
def fit( self, *, cov_type: str = "robust", debiased: bool = False, lsmr_options: Optional[Dict[str, Union[float, bool]]] = None, use_cache: bool = True, **cov_config: Any, ) -> AbsorbingLSResults: """ Estimate model parameters Parameters ---------- cov_type : str, optional Name of covariance estimator to use. Supported covariance estimators are: * 'unadjusted', 'homoskedastic' - Classic homoskedastic inference * 'robust', 'heteroskedastic' - Heteroskedasticity robust inference * 'kernel' - Heteroskedasticity and autocorrelation robust inference * 'cluster' - One-way cluster dependent inference. Heteroskedasticity robust debiased : bool, optional Flag indicating whether to debiased the covariance estimator using a degree of freedom adjustment. **cov_config Additional parameters to pass to covariance estimator. The list of optional parameters differ according to ``cov_type``. See the documentation of the alternative covariance estimators for the complete list of available commands. lsmr_options : dict Dictionary of options to pass to scipy.sparse.linalg.lsmr use_cache : bool 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. Returns ------- AbsorbingLSResults Results container Notes ----- Additional covariance parameters depend on specific covariance used. The see the docstring of specific covariance estimator for a list of supported options. Defaults are used if no covariance configuration is provided. 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. See also -------- linearmodels.iv.covariance.HomoskedasticCovariance linearmodels.iv.covariance.HeteroskedasticCovariance linearmodels.iv.covariance.KernelCovariance linearmodels.iv.covariance.ClusteredCovariance """ if self._absorbed_dependent is None: self._first_time_fit(use_cache, lsmr_options) self._x = exog_resid = to_numpy(self.absorbed_exog) dep_resid = to_numpy(self.absorbed_dependent) if self._exog.shape[1] == 0: params = empty((0, 1)) else: if exog_resid.shape[1]: check_absorbed(exog_resid, self.exog.cols) params = lstsq(exog_resid, dep_resid, rcond=None)[0] self._num_params += exog_resid.shape[1] cov_estimator = COVARIANCE_ESTIMATORS[cov_type] cov_config["debiased"] = debiased cov_config["kappa"] = 0.0 cov_config_copy = {k: v for k, v in cov_config.items()} if "center" in cov_config_copy: del cov_config_copy["center"] cov_estimator_inst = cov_estimator(exog_resid, dep_resid, exog_resid, params, **cov_config_copy) results = {"kappa": 0.0, "liml_kappa": 0.0} pe = self._post_estimation(params, cov_estimator_inst, cov_type) results.update(pe) results["df_model"] = self._num_params return AbsorbingLSResults(results, self)