moderndid.compute_ucb#
- moderndid.compute_ucb(y, x, w, x_eval=None, alpha=0.05, boot_num=99, basis='tensor', j_x_degree=3, j_x_segments=None, k_w_degree=4, k_w_segments=None, knots='uniform', ucb_h=True, ucb_deriv=True, deriv_index=1, deriv_order=1, w_min=None, w_max=None, x_min=None, x_max=None, seed=None, selection_result=None)[source]#
Compute uniform confidence bands for nonparametric instrumental variables.
Constructs simultaneous confidence bands for the structural function \(h_0\) and its derivatives \(\partial^a h_0\). For a fixed sieve dimension \(J\), the bands are constructed by under-smoothing, which requires \(J\) to be larger than the optimal dimension for estimation. The confidence bands are given by
\[C_{n,J}(x) = \left[\hat{h}_J(x) \pm z_{1-\alpha,J}^* \hat{\sigma}_J(x)\right],\]where \(\hat{\sigma}_J(x)\) is the estimated standard error and \(z_{1-\alpha,J}^*\) is the \((1-\alpha)\) quantile of the supremum of a multiplier bootstrap process given by
\[\sup_{x \in \mathcal{X}} \left| \frac{D_J^*(x)}{\hat{\sigma}_J(x)} \right| = \sup_{x \in \mathcal{X}} \left| \frac{(\psi^J(x))' \mathbf{M}_J \hat{\mathbf{u}}_J^*}{\hat{\sigma}_J(x)} \right|,\]where \(\hat{\mathbf{u}}_J^*\) contains residuals multiplied by IID \(N(0,1)\) draws. This approach ensures that the bias of the estimator is asymptotically negligible relative to the sampling uncertainty, but at the cost of slower convergence rates for the confidence bands.
When a data-driven dimension \(\tilde{J}\) is selected, this function routes to the procedure from [2] to construct honest and adaptive uniform confidence bands, which contract at the minimax optimal rate.
- Parameters:
- y
numpy.ndarray Dependent variable vector of length \(n\).
- x
numpy.ndarray Endogenous regressor matrix of shape \((n, p_x)\).
- w
numpy.ndarray Instrument matrix of shape \((n, p_w)\).
- x_eval
numpy.ndarray, optional Evaluation points for \(X\). If None, uses \(x\).
- alpha
float, default=0.05 Significance level (1-alpha confidence level).
- boot_num
int, default=99 Number of bootstrap replications.
- basis{“tensor”, “additive”, “glp”}, default=”tensor”
Type of basis for multivariate X.
- j_x_degree
int, default=3 Degree of B-spline basis for \(X\).
- j_x_segments
int, optional Number of segments for \(X\) basis. If None, chosen automatically.
- k_w_degree
int, default=4 Degree of B-spline basis for \(W\).
- k_w_segments
int, optional Number of segments for \(W\) basis. If None, chosen automatically.
- knots{“uniform”, “quantiles”}, default=”uniform”
Knot placement method.
- ucb_hbool, default=True
Whether to compute confidence bands for function estimates.
- ucb_derivbool, default=True
Whether to compute confidence bands for derivative estimates.
- deriv_index
int, default=1 Index (1-based) of \(X\) variable for derivative computation.
- deriv_order
int, default=1 Order of derivative to compute.
- w_min
float, optional Minimum value for \(W\) range.
- w_max
float, optional Maximum value for \(W\) range.
- x_min
float, optional Minimum value for \(X\) range.
- x_max
float, optional Maximum value for \(X\) range.
- seed
int, optional Random seed for bootstrap.
- selection_result
dict, optional Result from data-driven selection.
- y
- Returns:
NPIVResultNPIV results with uniform confidence bands included.
See also
compute_cck_ucbCompute honest and adaptive UCBs
References
[1]Chen, X., & Christensen, T. M. (2018). Optimal sup-norm rates and uniform inference on nonlinear functionals of nonparametric IV regression. Quantitative Economics, 9(1), 39-84. https://arxiv.org/abs/1508.03365.
[2]Chen, X., Christensen, T. M., & Kankanala, S. (2024). Adaptive Estimation and Uniform Confidence Bands for Nonparametric Structural Functions and Elasticities. https://arxiv.org/abs/2107.11869.