| npsemihat | R Documentation |
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.
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,
...)
These arguments identify the fitted bandwidth object, training data, and evaluation data.
bws |
A fitted bandwidth object. |
exdat |
Evaluation |
txdat |
Training |
These arguments control operator output, derivative selection, finite-difference compatibility, and apply-mode right-hand sides.
fd.step |
Compatibility argument for |
output |
Either |
s |
For |
y |
Optional response vector or matrix for apply mode. |
These arguments supply the additional z data used by partially linear and smooth-coefficient models.
ezdat |
Evaluation |
tzdat |
Training |
These arguments control smooth-coefficient iteration, leave-one-out behavior, and ridge stabilization.
iterate |
Logical; |
leave.one.out |
Logical; leave-one-out kernel weights for |
ridge |
Base ridge term for local linear solves in |
Reserved for future extensions.
... |
Reserved for future extensions. |
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.
If output = "matrix", returns a hat matrix H. If
output = "apply", returns H y (or H Y for matrix
right-hand-side input).
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.