Skip to contents

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", "constraint"),
           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", "constraint"),
           ...)

npscoefhat(bws,
           txdat = stop("training data 'txdat' missing"),
           tzdat = NULL,
           exdat = txdat,
           ezdat = tzdat,
           y = NULL,
           output = c("matrix", "apply", "constraint"),
           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" for the hat matrix, "apply" for direct application to y, or "constraint" for the row-weighted transpose t(H) * y. Note that npplreghat() retains "apply" as its default for historical compatibility.

s

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

y

Optional response vector or matrix for apply mode. For output = "constraint", y is required and must be a vector or one-column object. When the fitted response is a factor, factor payloads use its retained numerical level coding, including numeric level labels; payload levels are aligned to the fitted levels. Numeric vectors and matrices are used as supplied.

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 the supplied base (zero by default) and then increments by 1/n.train as needed for stable solves. The ridge is expressed in the normalized kernel-weight units of the matrix output; categorical profile application converts it to the equivalent profile-system scale.

Additional Arguments

Reserved for future extensions.

...

Reserved for future extensions.

Value

If output = "matrix", returns a hat matrix \(H\). If output = "apply", returns \(H y\) (or \(H Y\) for matrix right-hand-side input). If output = "constraint", returns the constraint design matrix \(\operatorname{diag}(y)H'\) as represented in R by t(H) * y.

Details

For local-constant and degree-zero local-polynomial npindexhat means, every finite nonzero kernel-weight sum is used without an epsilon floor. An explicitly supplied external evaluation row with all computed weights zero returns NA with a warning, preserving its position in matrix and applied outputs. This does not distinguish geometric absence from weights that have underflowed. Signed cancellation and nonfinite normalizing sums are errors. Required internal and bootstrap computations do not omit undefined rows or replications.

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.

For output = "constraint", the selected operator is first defined exactly as in output = "matrix" and the return value is t(H) * y. This is a convenience route for constrained quadratic-programming workflows; it does not solve a constrained estimation problem and it does not change the meaning of output = "apply".

Examples

if (FALSE) { # \dontrun{
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 
iA <- npindexhat(bws = ibw, txdat = data.frame(x, x2 = x^2),
                 y = y, output = "constraint")
all.equal(iA, t(iH) * y)
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)
} # }