How to use the linearmodels.iv.covariance.HomoskedasticCovariance function in linearmodels

To help you get started, we’ve selected a few linearmodels examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bashtage / linearmodels / linearmodels / iv / gmm.py View on Github external
    @property
    def config(self):
        """
        Weight estimator configuration

        Returns
        -------
        config : dict
            Dictionary containing weight estimator configuration information
        """
        return {'center': self._center,
                'clusters': self._clusters,
                'debiased': self._debiased}


class IVGMMCovariance(HomoskedasticCovariance):
    """
    Covariance estimation for GMM models

    Parameters
    ----------
    x : ndarray
        Model regressors (nobs by nvar)
    y : ndarray
        Series ,modeled (nobs by 1)
    z : ndarray
        Instruments used for endogenous regressors (nobs by ninstr)
    params : ndarray
        Estimated model parameters (nvar by 1)
    w : ndarray
        Weighting matrix used in GMM estimation
    cov_type : str, optional
github bashtage / linearmodels / linearmodels / iv / covariance.py View on Github external
eps = self.eps

        return self._scale * eps.T @ eps / nobs

    @property
    def debiased(self) -> bool:
        """Flag indicating if covariance is debiased"""
        return self._debiased

    @property
    def config(self) -> Dict[str, Any]:
        return {'debiased': self.debiased,
                'kappa': self._kappa}


class HeteroskedasticCovariance(HomoskedasticCovariance):
    r"""
    Covariance estimation for heteroskedastic data

    Parameters
    ----------
    x : ndarray
        Model regressors (nobs by nvar)
    y : ndarray
        Series ,modeled (nobs by 1)
    z : ndarray
        Instruments used for endogenous regressors (nobs by ninstr)
    params : ndarray
        Estimated model parameters (nvar by 1)
    debiased : bool, optional
        Flag indicating whether to use a small-sample adjustment
    kappa : float, optional
github bashtage / linearmodels / linearmodels / iv / covariance.py View on Github external
eps = self.eps

        return self._scale * eps.T @ eps / nobs

    @property
    def debiased(self):
        """Flag indicating if covariance is debiased"""
        return self._debiased

    @property
    def config(self):
        return {'debiased': self.debiased,
                'kappa': self._kappa}


class HeteroskedasticCovariance(HomoskedasticCovariance):
    r"""
    Covariance estimation for heteroskedastic data

    Parameters
    ----------
    x : ndarray
        Model regressors (nobs by nvar)
    y : ndarray
        Series ,modeled (nobs by 1)
    z : ndarray
        Instruments used for endogenous regressors (nobs by ninstr)
    params : ndarray
        Estimated model parameters (nvar by 1)
    debiased : bool, optional
        Flag indicating whether to use a small-sample adjustment
    kappa : float, optional
github bashtage / linearmodels / linearmodels / iv / model.py View on Github external
HomoskedasticWeightMatrix, IVGMMCovariance,
                                 KernelWeightMatrix,
                                 OneWayClusteredWeightMatrix)
from linearmodels.iv.results import IVGMMResults, IVResults, OLSResults
from linearmodels.typing import Numeric, OptionalNumeric
from linearmodels.typing.data import ArrayLike, OptionalArrayLike
from linearmodels.utility import (WaldTestStatistic, has_constant, inv_sqrth,
                                  missing_warning)

IVResultType = Type[Union[IVResults, IVGMMResults, OLSResults]]

__all__ = ['COVARIANCE_ESTIMATORS', 'WEIGHT_MATRICES', 'IVGMM', 'IVLIML', 'IV2SLS',
           'IVGMMCUE', '_OLS']

COVARIANCE_ESTIMATORS = {'homoskedastic': HomoskedasticCovariance,
                         'unadjusted': HomoskedasticCovariance,
                         'HomoskedasticCovariance': HomoskedasticCovariance,
                         'homo': HomoskedasticCovariance,
                         'robust': HeteroskedasticCovariance,
                         'heteroskedastic': HeteroskedasticCovariance,
                         'HeteroskedasticCovariance': HeteroskedasticCovariance,
                         'hccm': HeteroskedasticCovariance,
                         'kernel': KernelCovariance,
                         'KernelCovariance': KernelCovariance,
                         'one-way': ClusteredCovariance,
                         'clustered': ClusteredCovariance,
                         'OneWayClusteredCovariance': ClusteredCovariance}

WEIGHT_MATRICES = {'unadjusted': HomoskedasticWeightMatrix,
                   'homoskedastic': HomoskedasticWeightMatrix,
                   'robust': HeteroskedasticWeightMatrix,
                   'heteroskedastic': HeteroskedasticWeightMatrix,
github bashtage / linearmodels / linearmodels / iv / covariance.py View on Github external
super(HeteroskedasticCovariance, self).__init__(x, y, z, params, debiased, kappa)
        self._name = 'Robust Covariance (Heteroskedastic)'

    @property
    def s(self):
        """Heteroskedasticity-robust score covariance estimate"""
        x, z, eps = self.x, self.z, self.eps
        nobs, nvar = x.shape
        pinvz = self._pinvz
        xhat_e = z @ (pinvz @ x) * eps
        s = xhat_e.T @ xhat_e / nobs

        return self._scale * s


class KernelCovariance(HomoskedasticCovariance):
    r"""
    Kernel weighted (HAC) covariance estimation

    Parameters
    ----------
    x : ndarray
        Model regressors (nobs by nvar)
    y : ndarray
        Series ,modeled (nobs by 1)
    z : ndarray
        Instruments used for endogenous regressors (nobs by ninstr)
    params : ndarray
        Estimated model parameters (nvar by 1)
    kernel : str
        Kernel name. Supported kernels are:
github bashtage / linearmodels / linearmodels / iv / covariance.py View on Github external
super(HeteroskedasticCovariance, self).__init__(x, y, z, params, debiased, kappa)
        self._name = 'Robust Covariance (Heteroskedastic)'

    @property
    def s(self) -> ndarray:
        """Heteroskedasticity-robust score covariance estimate"""
        x, z, eps = self.x, self.z, self.eps
        nobs, nvar = x.shape
        pinvz = self._pinvz
        xhat_e = z @ (pinvz @ x) * eps
        s = xhat_e.T @ xhat_e / nobs

        return self._scale * s


class KernelCovariance(HomoskedasticCovariance):
    r"""
    Kernel weighted (HAC) covariance estimation

    Parameters
    ----------
    x : ndarray
        Model regressors (nobs by nvar)
    y : ndarray
        Series ,modeled (nobs by 1)
    z : ndarray
        Instruments used for endogenous regressors (nobs by ninstr)
    params : ndarray
        Estimated model parameters (nvar by 1)
    kernel : str
        Kernel name. Supported kernels are:
github bashtage / linearmodels / linearmodels / iv / covariance.py View on Github external
self._bandwidth = bw
        w = self._kernels[kernel](bw, nobs - 1)

        s = _cov_kernel(xhat_e, w)

        return self._scale * s

    @property
    def config(self) -> Dict[str, Any]:
        return {'debiased': self.debiased,
                'bandwidth': self._bandwidth,
                'kernel': self._kernel,
                'kappa': self._kappa}


class ClusteredCovariance(HomoskedasticCovariance):
    r"""
    Covariance estimation for clustered data

    Parameters
    ----------
    x : ndarray
        Model regressors (nobs by nvar)
    y : ndarray
        Series ,modeled (nobs by 1)
    z : ndarray
        Instruments used for endogenous regressors (nobs by ninstr)
    params : ndarray
        Estimated model parameters (nvar by 1)
    debiased : bool, optional
        Flag indicating whether to use a small-sample adjustment
    clusters : ndarray, optional
github bashtage / linearmodels / linearmodels / iv / covariance.py View on Github external
self._bandwidth = bw
        w = self._kernels[kernel](bw, nobs - 1)

        s = _cov_kernel(xhat_e, w)

        return self._scale * s

    @property
    def config(self):
        return {'debiased': self.debiased,
                'bandwidth': self._bandwidth,
                'kernel': self._kernel,
                'kappa': self._kappa}


class ClusteredCovariance(HomoskedasticCovariance):
    r"""
    Covariance estimation for clustered data

    Parameters
    ----------
    x : ndarray
        Model regressors (nobs by nvar)
    y : ndarray
        Series ,modeled (nobs by 1)
    z : ndarray
        Instruments used for endogenous regressors (nobs by ninstr)
    params : ndarray
        Estimated model parameters (nvar by 1)
    debiased : bool, optional
        Flag indicating whether to use a small-sample adjustment
    clusters : ndarray, optional