npreghat: Nonparametric Regression Hat Operator

View source: R/np.reghat.R

npreghatR Documentation

Nonparametric Regression Hat Operator

Description

Constructs 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"),
         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"),
        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 rbandwidth or npregression.

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 explicit exdat/newdata.

ridge

Base diagonal regularization used when local systems are ill-conditioned. The ridge sequence starts at 0 (no regularization) and then increments by 1/n.train as needed for stable solves.

s

Derivative multi-index over continuous predictors.

Method Objects

This argument identifies a fitted hat-operator object supplied to an S3 method.

object

An object returned by npreghat.

Operator Output

These arguments control whether the operator is returned as a matrix or applied directly.

output

Either "matrix" for the hat matrix or "apply" for direct application to y.

y

Optional response vector or matrix for apply mode.

Additional Arguments

Further arguments are passed to methods.

...

Additional arguments passed to methods.

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.

Value

Either a hat matrix (class "npreghat") or the applied result H^{(s)} y, depending on output.

Examples

## Not run: 
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 
ghat <- npreg(bws = bw)
head(cbind(fitted(ghat), H.fitted), n = 2L)

## End(Not run)

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