|
| 1 | +Local-Linear Infrastructure |
| 2 | +=========================== |
| 3 | + |
| 4 | +Kernels, kernel-moment constants, univariate local-linear regression at a |
| 5 | +boundary, the MSE-optimal bandwidth selector, and the bias-corrected |
| 6 | +local-linear fit. |
| 7 | + |
| 8 | +This module ships the nonparametric building blocks that |
| 9 | +:class:`~diff_diff.HeterogeneousAdoptionDiD` composes for its continuous-dose |
| 10 | +fit paths (``continuous_at_zero`` and ``continuous_near_d_lower``); see |
| 11 | +:doc:`had` for the estimator that consumes them. The components are also |
| 12 | +usable on their own for any one-sided boundary local-linear regression |
| 13 | +problem with a strictly nonnegative running variable. |
| 14 | + |
| 15 | +The selector and bias correction are ports of the Calonico-Cattaneo-Farrell |
| 16 | +(2018) plug-in bandwidth and Calonico-Cattaneo-Titiunik (2014) robust-bias |
| 17 | +correction from the R ``nprobust`` package; methodology context lives in |
| 18 | +:doc:`had` and ``docs/methodology/REGISTRY.md``. |
| 19 | + |
| 20 | +Kernels |
| 21 | +------- |
| 22 | + |
| 23 | +Bounded one-sided kernels on ``[0, 1]`` for boundary-point nonparametric |
| 24 | +regression. The library normalizes the Epanechnikov and triangular kernels |
| 25 | +to ``int_0^1 k(u) du = 1/2``; the uniform kernel uses |
| 26 | +``int_0^1 k(u) du = 1``. |
| 27 | + |
| 28 | +.. autofunction:: diff_diff.epanechnikov_kernel |
| 29 | + |
| 30 | +.. autofunction:: diff_diff.triangular_kernel |
| 31 | + |
| 32 | +.. autofunction:: diff_diff.uniform_kernel |
| 33 | + |
| 34 | +.. autodata:: diff_diff.KERNELS |
| 35 | + :annotation: : dict[str, Callable[[np.ndarray], np.ndarray]] |
| 36 | + :no-value: |
| 37 | + |
| 38 | + Mapping from kernel name (``"epanechnikov"`` / ``"triangular"`` / |
| 39 | + ``"uniform"``) to its callable evaluator on ``[0, 1]``. Pass the name |
| 40 | + string (not the callable) to ``local_linear_fit`` and |
| 41 | + ``mse_optimal_bandwidth`` via their ``kernel=`` argument. |
| 42 | + |
| 43 | +.. autofunction:: diff_diff.kernel_moments |
| 44 | + |
| 45 | +Boundary local-linear fit |
| 46 | +------------------------- |
| 47 | + |
| 48 | +Kernel-weighted OLS estimator of the conditional mean |
| 49 | +``m(d0) := E[Y | D = d0]`` at the boundary of ``D``'s support. |
| 50 | + |
| 51 | +.. autofunction:: diff_diff.local_linear_fit |
| 52 | + |
| 53 | +.. autoclass:: diff_diff.LocalLinearFit |
| 54 | + :members: |
| 55 | + :undoc-members: |
| 56 | + :show-inheritance: |
| 57 | + |
| 58 | +MSE-optimal bandwidth selector |
| 59 | +------------------------------ |
| 60 | + |
| 61 | +Plug-in MSE-optimal bandwidth (Calonico-Cattaneo-Farrell 2018) for the |
| 62 | +boundary local-linear fit. Returns ``BandwidthResult`` carrying the final |
| 63 | +bandwidth ``h_mse`` plus the per-stage diagnostics needed to audit the |
| 64 | +selector against the R ``nprobust`` reference. |
| 65 | + |
| 66 | +.. autofunction:: diff_diff.mse_optimal_bandwidth |
| 67 | + |
| 68 | +.. autoclass:: diff_diff.BandwidthResult |
| 69 | + :members: |
| 70 | + :undoc-members: |
| 71 | + :show-inheritance: |
| 72 | + |
| 73 | +Bias-corrected local-linear fit |
| 74 | +------------------------------- |
| 75 | + |
| 76 | +Calonico-Cattaneo-Titiunik (2014) robust-bias-corrected boundary |
| 77 | +estimator. Composes the bandwidth selector and the local-linear fit and |
| 78 | +returns a ``BiasCorrectedFit`` with point estimate, robust standard error, |
| 79 | +and 95% confidence interval. |
| 80 | + |
| 81 | +.. autofunction:: diff_diff.bias_corrected_local_linear |
| 82 | + |
| 83 | +.. autoclass:: diff_diff.BiasCorrectedFit |
| 84 | + :members: |
| 85 | + :undoc-members: |
| 86 | + :show-inheritance: |
0 commit comments