Experimental Hat Operators for Semiparametric Estimators
npsemihat.RdConstructs 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 classsibandwidth,npplreghat()requires classplbandwidth, andnpscoefhat()requires classscbandwidth.- exdat
Evaluation
xdata.- txdat
Training
xdata.
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 currents=1route uses the canonical exact derivative operator rather than finite-differencing the fit operator.- output
Either
"matrix"for the hat matrix,"apply"for direct application toy, or"constraint"for the row-weighted transposet(H) * y. Note thatnpplreghat()retains"apply"as its default for historical compatibility.- s
For
npindexhat,s=0returns fit operator ands=1returns index-derivative operator.- y
Optional response vector or matrix for apply mode. For
output = "constraint",yis required and must be a vector or one-column object.
Partially Linear And Smooth-Coefficient Data
These arguments supply the additional z data used by 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 supportsiterate = FALSEonly.- leave.one.out
Logical; leave-one-out kernel weights for
npscoefhat. This currently requires evaluationzdata to match trainingzdata.- ridge
Base ridge term for local linear solves in
npscoefhat; must be a non-negative finite scalar. The ridge sequence starts at0(no regularization) and then increments by1/n.trainas needed for stable solves.
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
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)
} # }