npsemihat: Experimental Hat Operators for Semiparametric Estimators

npsemihatR Documentation

Experimental Hat Operators for Semiparametric Estimators

Description

Constructs hat operators for semiparametric estimators so that fitted values or bootstrap draws can be computed by matrix application in one step. These interfaces are currently experimental.

Usage

npindexhat(bws,
           txdat = stop("training data 'txdat' missing"),
           exdat = txdat,
           y = NULL,
           output = c("matrix", "apply"),
           s = 0L,
           fd.step = NULL,
           ...)

npplreghat(bws,
           txdat = stop("training data 'txdat' missing"),
           tzdat = stop("training data 'tzdat' missing"),
           exdat = txdat,
           ezdat = tzdat,
           y = NULL,
           output = c("apply", "matrix"),
           ...)

npscoefhat(bws,
           txdat = stop("training data 'txdat' missing"),
           tzdat = NULL,
           exdat = txdat,
           ezdat = tzdat,
           y = NULL,
           output = c("matrix", "apply"),
           ridge = 0,
           iterate = FALSE,
           leave.one.out = FALSE,
           ...)

Arguments

Data, Bandwidth Inputs And Formula Interface

These arguments identify the fitted bandwidth object, training data, and evaluation data.

bws

A fitted bandwidth object. npindexhat() requires class sibandwidth, npplreghat() requires class plbandwidth, and npscoefhat() requires class scbandwidth.

exdat

Evaluation x data.

txdat

Training x data.

Operator Output And Derivatives

These arguments control operator output, derivative selection, finite-difference compatibility, and apply-mode right-hand sides.

fd.step

Compatibility argument for npindexhat(..., s=1). If supplied it must be a positive finite scalar, but the current s=1 route uses the canonical exact derivative operator rather than finite-differencing the fit operator.

output

Either "matrix" or "apply".

s

For npindexhat, s=0 returns fit operator and s=1 returns index-derivative operator.

y

Optional response vector or matrix for apply mode.

Partially Linear And Smooth-Coefficient Data

These arguments supply the additional z data used by partially linear and smooth-coefficient models.

ezdat

Evaluation z data.

tzdat

Training z data for partially linear and smooth-coefficient models.

Smooth-Coefficient Controls

These arguments control smooth-coefficient iteration, leave-one-out behavior, and ridge stabilization.

iterate

Logical; npscoefhat() currently supports iterate = FALSE only.

leave.one.out

Logical; leave-one-out kernel weights for npscoefhat. This currently requires evaluation z data to match training z data.

ridge

Base ridge term for local linear solves in npscoefhat; must be a non-negative finite scalar. The ridge sequence starts at 0 (no regularization) and then increments by 1/n.train as needed for stable solves.

Additional Arguments

Reserved for future extensions.

...

Reserved for future extensions.

Details

These operators are intended for fixed-X workflows such as one-shot wild bootstrap calculations where many response draws are projected through the same operator. The implementation is intentionally conservative: class and scalar argument contracts are validated explicitly, and unsupported iterative npscoefhat() paths fail fast. npscoefhat() inherits regtype/LP-basis controls from the supplied scbandwidth object. For non-fixed npscoef bootstrap plotting, these operators can support a frozen approximation, but they do not remove the need to recompute the local smooth-coefficient vector itself for each resample: the local weighted systems depend on the resample weights/counts at each evaluation point, so unlike npplreg there is no single global coefficient vector to update once per draw.

Method-specific argument map: npindexhat() uses s; fd.step is accepted for compatibility but the current s=1 route uses the canonical exact derivative operator; npplreghat() and npscoefhat() use tzdat/ezdat; npscoefhat() additionally uses ridge, iterate, and leave.one.out.

Value

If output = "matrix", returns a hat matrix H. If output = "apply", returns H y (or H Y for matrix right-hand-side input).

Examples

## Not run: 
set.seed(42)
n <- 100
x <- runif(n)
z <- runif(n)
y <- sin(2*pi*x) + 0.5 * z + rnorm(n, sd = 0.1)

tx <- data.frame(x = x)
tz <- data.frame(z = z)

ibw <- npindexbw(xdat = data.frame(x, x2 = x^2), ydat = y,
                 bws = c(0.5, 1.0, 1.0), bandwidth.compute = FALSE)
iH <- npindexhat(bws = ibw, txdat = data.frame(x, x2 = x^2), output = "matrix")
iH.fitted <- iH 
ifit <- npindex(bws = ibw, txdat = data.frame(x, x2 = x^2), tydat = y)
head(cbind(fitted(ifit), iH.fitted), n = 2L)

pbw <- npplregbw(xdat = tx, zdat = tz, ydat = y,
                 bws = matrix(c(0.2, 0.2), nrow = 2L, ncol = 1L),
                 bandwidth.compute = FALSE)
pH <- npplreghat(bws = pbw, txdat = tx, tzdat = tz, output = "matrix")
pH.fitted <- pH 
pfit <- npplreg(bws = pbw, txdat = tx, tydat = y, tzdat = tz)
head(cbind(fitted(pfit), pH.fitted), n = 2L)

sbw <- npscoefbw(xdat = tx, zdat = tz, ydat = y,
                 bws = 0.2, bandwidth.compute = FALSE)
sH <- npscoefhat(bws = sbw, txdat = tx, tzdat = tz,
                 output = "matrix", iterate = FALSE)
sH.fitted <- sH 
sfit <- npscoef(bws = sbw, txdat = tx, tydat = y, tzdat = tz,
                iterate = FALSE)
head(cbind(fitted(sfit), sH.fitted), n = 2L)

## End(Not run)

np documentation built on May 3, 2026, 1:07 a.m.