linearmodels.iv.gmm.KernelWeightMatrix¶
-
class linearmodels.iv.gmm.KernelWeightMatrix(kernel: str =
'bartlett', bandwidth: int | None =None, center: bool =False, debiased: bool =False, optimal_bw: bool | None =None)[source]¶ Heteroskedasticity, autocorrelation robust weight estimation.
- Parameters:¶
- kernel: str =
'bartlett'¶ Name of kernel weighting function to use. 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: int | None =
None¶ Bandwidth to use when computing kernel weights. If not provided, the bandwidth is selected by
optimal_bw.- 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.
- 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.
- kernel: str =
See also
linearmodels.iv.covariance.kernel_weight_bartlettKernel weights from a Bartlett kernel.
linearmodels.iv.covariance.kernel_weight_parzenKernel weights from a Parzen kernel.
linearmodels.iv.covariance.kernel_weight_quadratic_spectralKernel weights from a quadratic-spectral kernel.
Notes
The weight matrix is
\[\begin{split}g_i & =z_i \epsilon_i \\ W & =n^{-1}(\Gamma_0+\sum_{j=1}^{n-1}k(j)(\Gamma_j+\Gamma_j')) \\ \Gamma_j & =\sum_{i=j+1}^n g'_i g_{i-j}\end{split}\]where \(k(j)\) is the kernel weight for lag j and \(z_i\) contains both the exogenous regressors and instruments.
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.IVGMMCUEestimates the bandwidth once, from the residuals of the first step estimates, and uses it in every evaluation of its objective function.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
weight_matrix(x, z, eps)Compute the covariance of the moment conditions.
Properties
Actual bandwidth used in estimating the weight matrix.
Weight estimator configuration.