linearmodels.system.gmm.KernelWeightMatrix

class linearmodels.system.gmm.KernelWeightMatrix(center: bool = False, debiased: bool = False, kernel: str = 'bartlett', bandwidth: float | None = None, optimal_bw: bool | None = None)[source]

Heteroskedasticity and autocorrelation robust (HAC) weight estimation.

Parameters:
center: bool = False

Flag indicating whether to center the moment conditions by subtracting the mean before computing the weight matrix. The default is False.

debiased: bool = False

Flag indicating whether to use small-sample adjustments. The default is False.

kernel: str = 'bartlett'

Name of the kernel. The default is “bartlett”. The names are not case sensitive. Supported kernels are:

  • ”bartlett”, “newey-west” - Bartlett’s kernel

  • ”parzen”, “gallant” - Parzen’s kernel

  • ”qs”, “quadratic-spectral”, “andrews” - Quadratic spectral kernel

bandwidth: float | None = None

Non-negative bandwidth to use for the kernel. If not provided, the bandwidth is selected by optimal_bw.

optimal_bw: bool | None = None

Flag indicating whether to estimate the bandwidth from the data when bandwidth is not provided. If False, nobs - 2 is used. If True, the bandwidth is estimated using kernel_optimal_bandwidth(), which needs at least 4 observations with the Bartlett kernel, 5 with the Parzen kernel and 6 with the quadratic spectral kernel. The default also estimates the bandwidth, but it issues a DefaultBandwidthWarning since it changed in 7.1.

Notes

The weight matrix estimator is

\[\begin{split}W & = \hat{\Gamma}_0+\sum_{i=1}^{n-1} w_i (\hat{\Gamma}_i+\hat{\Gamma}_i^\prime) \\ \hat{\Gamma}_j & = n^{-1}\sum_{i=1}^{n-j} g'_ig_{i+j} \\ g_i & = (z_{1i}\epsilon_{1i},z_{2i}\epsilon_{2i},\ldots,z_{ki}\epsilon_{ki})\end{split}\]

where \(g_i\) is the vector of scores across all equations for observation i and \(w_j\) are the kernel weights which depend on the selected kernel and bandwidth. \(z_{ji}\) is the vector of instruments for equation j and \(\epsilon_{ji}\) is the error for equation j for observation i. This form allows for heteroskedasticity and autocorrelation between the moment conditions.

If neither bandwidth nor optimal_bw is given, the bandwidth is estimated from the data every time that the weight matrix is computed. In 7.0 and earlier the default was nobs - 2, which is not a consistent estimator of the covariance of the moment conditions. Using the default issues a DefaultBandwidthWarning (a UserWarning), once for each instance. The previous behavior is restored by optimal_bw=False or by bandwidth=nobs - 2. Passing bandwidth or optimal_bw silences the warning, and optimal_bw=True selects the new default without it.

Changed in version 7.1: weight_matrix raises a ValueError if the bandwidth is estimated from the data and there are fewer observations than the kernel needs (see optimal_bw), or if the estimated bandwidth is not finite. Pass bandwidth or optimal_bw=False to use the weight matrix with fewer observations. Earlier versions raised “cannot convert float infinity to integer” (an OverflowError) or “cannot convert float NaN to integer” for some data when optimal_bw was True, and used a bandwidth of nobs - 1, or another bandwidth, for other data.

Methods

sigma(eps, x)

Estimate residual covariance.

weight_matrix(x, z, eps, *[, sigma])

Construct a GMM weight matrix for a model.

Properties

bandwidth

Bandwidth used to estimate covariance of moment conditions.

config

Weight estimator configuration.

kernel

Kernel used in estimation.