Skip to content

linearmodels/kernel-default-bandwidth

Rule kernel-default-bandwidth
Pack linearmodels
Severity warning
Fix unsafe, with xpd check --fix --unsafe-fixes
Library versions every version

The default kernel bandwidth changed in linearmodels 7.1, so results change between versions and 7.1 warns. Pass bandwidth= or optimal_bw=True.

result = IVGMM(y, exog, endog, instruments, weight_type="kernel").fit()
result = IVGMM(y, exog, endog, instruments, weight_type="kernel", optimal_bw=True).fit()

The rule reports weight_type="kernel" on IVGMM, IVGMMCUE and IVSystemGMM, and cov_type="kernel" in fit of IVGMM and IVGMMCUE, with neither bandwidth nor optimal_bw. 7.1 changed the default bandwidth from nobs - 2 to one selected from the data, so the same code gives other numbers on 7.0 and on 7.1.

xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.

The unsafe fix adds optimal_bw=True. On 7.1 it gave estimates and standard errors bit equal to the default, without the warning, and on 7.0 it changes the bandwidth from nobs - 2 to the one selected from the data.

On the mroz data, the two releases gave the following numbers:

Form On 7.0 On 7.1
IVGMM(..., weight_type="kernel"), J statistic and first standard error 0.8022 and 0.43964 0.3794 and 0.43137, with DefaultBandwidthWarning
the same with optimal_bw=True 0.3794 and 0.43137 0.3794 and 0.43137
the same with bandwidth=4 0.43117 0.43117
IVGMM(...).fit(cov_type="kernel"), first standard error 0.35929 0.4658
the same with bandwidth=4 0.46795 0.46795

IVSystemGMM.fit(cov_type="kernel") and IV2SLS.fit(cov_type="kernel") gave the same numbers on both releases with no warning and are not reported.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

weight_type="kernel" with no bandwidth and no optimal_bw uses a default that linearmodels 7.1 changed, from nobs - 2 to a bandwidth selected from the data, and 7.1 gives DefaultBandwidthWarning. On the mroz data the J statistic of IVGMM went from 0.8022 on 7.0 to 0.3794 on 7.1. Write optimal_bw=True, which gives the numbers of 7.1 on both releases and no warning. A bandwidth of your own also gives the same numbers on both.

Browse the other rules of the linearmodels pack.