Basis Functions

hddid.polynomial_sieve_basis(z, degree)[source]

Construct a one-dimensional polynomial sieve basis with an intercept.

Builds the matrix [1, z, z^2, …, z^degree] for use as the nonparametric sieve in the partially-linear model Eq. (3.1).

Parameters:
  • z (ndarray of float, shape (n,)) – Scalar nonparametric variable values. Must be finite.

  • degree (int) – Maximum polynomial power (>= 0). The resulting basis has degree + 1 columns including the intercept.

Returns:

Polynomial basis matrix with column j equal to z^j.

Return type:

ndarray of float, shape (n, degree + 1)

Raises:

ValueError – If z is not one-dimensional, contains non-finite values, or degree is not a non-negative integer.

hddid.trigonometric_sieve_basis(z, degree)[source]

Construct a one-dimensional trigonometric sieve basis with an intercept.

Builds the matrix [1, cos(2*pi*z), sin(2*pi*z), …, cos(2*degree*pi*z), sin(2*degree*pi*z)] for use as the nonparametric sieve in Eq. (3.1).

Parameters:
  • z (ndarray of float, shape (n,)) – Scalar nonparametric variable values. Must be finite.

  • degree (int) – Number of harmonic pairs (>= 1). The resulting basis has 2*degree + 1 columns including the intercept.

Returns:

Trigonometric basis matrix.

Return type:

ndarray of float, shape (n, 2*degree + 1)

Raises:

ValueError – If z is not one-dimensional, contains non-finite values, or degree is not a positive integer.

hddid.bspline_sieve_basis(z, degree)[source]

Construct a B-spline sieve basis matrix.

B-splines have the optimal Bernstein constant O(1), superior to polynomial O(k^{d_z/2}) and trigonometric O(k^{d_z}) bases Ning, Peng, and Tao (2020).

Parameters:
  • z (ndarray, shape (n,)) – Scalar variable values.

  • degree (int) – Number of interior knots (>= 1). Cubic B-splines (order 4) are used. Total basis dimension = degree + 4.

Returns:

basis_matrix – B-spline basis functions evaluated at z. Includes a leading constant column for compatibility. One B-spline column is dropped to break the partition-of-unity constraint and ensure full column rank.

Return type:

ndarray, shape (n, degree + 4)

hddid.suggest_basis_degree(n, p, *, basis_family='polynomial', method='conservative')[source]

Suggest a basis function degree based on sample size and dimension.

Implements the truncation parameter selection heuristic from Ning, Peng, and Tao (2020), Assumption 6 and surrounding discussion.

The conservative rule uses k_n = floor(c * log(n)) with c chosen to satisfy the theoretical constraint k_n = o(sqrt(n) / sqrt(log(p))).

Parameters:
  • n (int) – Sample size (number of observations).

  • p (int) – Number of high-dimensional covariates.

  • basis_family (str, default "polynomial") – Basis function family (“polynomial” or “trigonometric”). Affects the Bernstein constant growth rate.

  • method (str, default "conservative") –

    Selection method. Currently supported:

    • ”conservative”: Uses k_n = floor(c * log(n)) with c calibrated to the theoretical upper bound.

    • ”upper_bound”: Returns the theoretical maximum k_n satisfying Assumption 6 constraints.

Returns:

Recommended basis degree (>= 1).

Return type:

int

Raises:

ValueError – If n <= 0, p <= 0, basis_family is invalid, or method is invalid.

Notes

The theoretical constraint from the paper is:

k_n = o(sqrt(n) / sqrt(log(p)))

For the conservative rule, we use c = 1.5 (middle of the paper’s suggested range [1, 3]) and then clip to the theoretical upper bound.

For polynomial basis, the effective constraint is tighter due to the Bernstein constant growth O(k^{d_z/2}) with d_z = 1.

Examples

>>> suggest_basis_degree(500, 100)
8
>>> suggest_basis_degree(1000, 200, basis_family="trigonometric")
4