| crshat | R Documentation |
Construct or apply the linear hat operator for fixed-structure CRS mean
regression fits. The helper is intended for fixed-X workflows such as
fast plot bootstrapping and constrained-estimation diagnostics.
crshat(object, ...)
## S3 method for class 'crs'
crshat(object,
newdata = NULL,
y = NULL,
output = c("matrix", "apply", "constraint"),
deriv = 0,
deriv.index = 1,
rcond.min = 1e-08,
use.svd.fallback = TRUE,
...)
object |
A fitted mean-regression object of class |
newdata |
Optional evaluation data. If omitted, the training data are used. |
y |
Optional response vector or matrix. Required for
|
output |
One of |
deriv |
Non-negative integer derivative order. |
deriv.index |
Positive integer identifying the continuous predictor whose derivative operator is requested. |
rcond.min |
Minimum reciprocal condition number used by the weighted least-squares primitive before falling back to QR/SVD policy. |
use.svd.fallback |
Logical value controlling the weighted least-squares fallback policy. |
... |
Additional arguments, currently unused. |
For a fitted CRS mean-regression object, crshat() returns the linear
operator mapping the training response to fitted values at newdata. The
default output="matrix" returns a dense matrix with class
c("crshat", "matrix"). The output="apply" route applies the same
operator to y and is preferable when many right-hand sides are needed.
The helper preserves the fitted object's fixed spline/kernel structure, including basis family, degree, segments, pruning state, categorical-kernel bandwidths, weights, and the package's weighted least-squares rank policy. It does not run bandwidth or degree selection.
For deriv > 0, crshat() returns the derivative operator
H^{(s)} such that H^{(s)} y matches the corresponding CRS
gradient prediction at newdata. This is the CRS analogue of
npreghat's derivative-selector behavior in np. Derivative operators
are available for fixed-structure mean CRS fits across additive, tensor, and
GLP bases, including categorical-kernel fits. If the requested derivative
order exceeds the fitted spline degree for that predictor, the returned
operator is zero.
Quantile CRS objects remain intentionally unsupported because quantile estimation is not linear in the response.
For output="matrix", a matrix of dimension
nrow(newdata) x nrow(training data). For output="apply", fitted
values produced by applying the operator to y. For
output="constraint", the transpose operator scaled by the supplied
one-column response vector.
crs, predict
set.seed(42)
x <- runif(30)
y <- sin(2 * pi * x) + rnorm(30, sd = 0.1)
fit <- crs(y ~ x, cv = "none", degree = 2, segments = 1,
display.warnings = FALSE, display.nomad.progress = FALSE)
nd <- data.frame(x = seq(0.1, 0.9, length.out = 5))
H <- crshat(fit, newdata = nd)
drop(H %*% fit$y)
crshat(fit, newdata = nd, output = "apply")
Hd <- crshat(fit, newdata = nd, deriv = 1, deriv.index = 1)
drop(Hd %*% fit$y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.