Nonparametric Regression Hat Operator
npreghat.RdConstructs nonparametric regression hat operators for npreg-compatible
bandwidth objects. The returned operator \(H^{(s)}\) maps responses to fitted
values or derivative estimates via \(H^{(s)} y\).
Usage
npreghat(bws, ...)
# S3 method for class 'formula'
npreghat(bws,
data = NULL,
newdata = NULL,
...)
# S3 method for class 'rbandwidth'
npreghat(bws,
txdat = stop("training data 'txdat' missing"),
exdat, y = NULL,
output = c("matrix", "apply", "constraint"),
basis = NULL,
bernstein.basis = NULL,
degree = NULL,
deriv = NULL,
leave.one.out = FALSE,
ridge = 0,
s = NULL,
...)
# S3 method for class 'npregression'
npreghat(bws,
txdat,
y,
...)
# S3 method for class 'npreghat'
predict(object,
newdata = NULL, y = NULL,
output = c("matrix", "apply", "constraint"),
s = attr(object, "s"),
leave.one.out = attr(object, "leave.one.out"),
deriv = NULL,
...)Arguments
Data, Bandwidth Inputs And Formula Interface
These arguments identify the fitted bandwidth object, formula/data interface, training data, and evaluation data.
- bws
An object of class
rbandwidthornpregression.- data
A data frame used with the formula interface.
- exdat
Optional evaluation predictors.
- newdata
Optional evaluation data for formula and predict methods.
- txdat
Training predictors.
Local-Polynomial Controls
These arguments control local-polynomial basis, degree, derivatives, leave-one-out behavior, and ridge stabilization.
- basis
Local polynomial basis:
"glp","additive", or"tensor".- bernstein.basis
Logical; use Bernstein basis for LP terms.
- degree
Optional local polynomial degree vector override (LP path).
- deriv
Convenience alias for
s.- leave.one.out
Logical; if
TRUE, compute in-sample leave-one-out hat weights. This cannot be combined with explicitexdat/newdata.- ridge
Base diagonal regularization used when local systems are ill-conditioned. The ridge sequence starts at
0(no regularization) and then increments by1/n.trainas needed for stable solves.- s
Derivative multi-index over continuous predictors.
Operator Output
These arguments control whether the operator is returned as a matrix, applied directly, or returned as a quadratic-programming constraint design matrix.
Details
For output = "matrix", the return value is a matrix with class
c("npreghat", "matrix") so it can be used directly in matrix products,
e.g. H %*% y. Attributes on the matrix store metadata used by
predict.npreghat.
For output = "apply", the function returns H^{(s)} y directly and
accepts matrix right-hand sides for one-shot bootstrap-style calculations.
For output = "constraint", the function returns t(H^{(s)}) * y,
the row-weighted transpose commonly used as the design matrix in
shape-constrained quadratic-programming examples. This is a convenience route
that is exactly equivalent to obtaining H with output = "matrix"
and then computing t(H) * y; it does not solve a constrained estimation
problem.
Value
Either a hat matrix (class "npreghat") or the applied result
H^{(s)} y, or the constraint design matrix t(H^{(s)}) * y,
depending on output.
Examples
if (FALSE) { # \dontrun{
data(cps71)
bw <- npregbw(xdat = cps71$age, ydat = cps71$logwage,
regtype = "ll", bandwidth.compute = FALSE, bws = 1.0)
H <- npreghat(bws = bw, txdat = data.frame(age = cps71$age))
H.fitted <- H
A <- npreghat(bws = bw, txdat = data.frame(age = cps71$age),
y = cps71$logwage, output = "constraint")
all.equal(A, t(H) * cps71$logwage)
ghat <- npreg(bws = bw)
head(cbind(fitted(ghat), H.fitted), n = 2L)
} # }