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
bandwidthis not provided. If False, nobs - 2 is used. If True, the bandwidth is estimated usingkernel_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 aDefaultBandwidthWarningsince it changed in 7.1.
- center: bool =
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
bandwidthnoroptimal_bwis given, the bandwidth is estimated from the data every time that the weight matrix is computed. In 7.0 and earlier the default wasnobs - 2, which is not a consistent estimator of the covariance of the moment conditions. Using the default issues aDefaultBandwidthWarning(aUserWarning), once for each instance. The previous behavior is restored byoptimal_bw=Falseor bybandwidth=nobs - 2. Passingbandwidthoroptimal_bwsilences the warning, andoptimal_bw=Trueselects the new default without it.Changed in version 7.1:
weight_matrixraises aValueErrorif the bandwidth is estimated from the data and there are fewer observations than the kernel needs (seeoptimal_bw), or if the estimated bandwidth is not finite. Passbandwidthoroptimal_bw=Falseto use the weight matrix with fewer observations. Earlier versions raised “cannot convert float infinity to integer” (anOverflowError) or “cannot convert float NaN to integer” for some data whenoptimal_bwwas 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 used to estimate covariance of moment conditions.
Weight estimator configuration.
Kernel used in estimation.