Predict from Gaussian Trend Filtering
Source:R/gaussian_trend_filtering.R
predict.gaussian.trend.filtering.fit.RdPredict from Gaussian Trend Filtering
Usage
# S3 method for class 'gaussian.trend.filtering.fit'
predict(
object,
newdata = NULL,
covariates = NULL,
offset = NULL,
type = c("response", "link"),
lambda.index = NULL,
allow.unconverged = FALSE,
...
)
# S3 method for class 'gaussian.trend.filtering.fit'
fitted(object, ...)
# S3 method for class 'gaussian.trend.filtering.fit'
residuals(object, ...)
# S3 method for class 'gaussian.trend.filtering.fit'
print(x, ...)Arguments
- object
A
gaussian.trend.filtering.fitobject.- newdata
Finite numeric predictor locations; default training locations.
- covariates
Additional predictor matrix, with the training column order.
- offset
Offset vector, required for new locations if used during fitting.
- type
"response"or"link"; both return fitted means because the Gaussian model uses the identity link.- lambda.index
Path indices; defaults to the CV selection if available, otherwise all supplied penalties.
- allow.unconverged
Explicitly allow predictions from failed fits.
- ...
Reserved for compatibility with generic methods.
- x
A fitted Gaussian trend-filtering object.
Value
A numeric vector for one path index, otherwise a matrix. Attributes
outside.range and lambda record boundary predictions and penalties.
Examples
x <- seq(0, 1, length.out = 20)
fit <- fit.gaussian.trend.filtering(x, 1+x-x^2, lambda = Inf)
predict(fit, c(0.25, 0.75))
#> [1] 1.1875 1.1875
#> attr(,"outside.range")
#> [1] FALSE FALSE
#> attr(,"lambda")
#> [1] Inf
head(fitted(fit))
#> [1] 1.000000 1.049861 1.094183 1.132964 1.166205 1.193906
head(residuals(fit))
#> [1] 3.330669e-16 2.220446e-16 2.220446e-16 0.000000e+00 0.000000e+00
#> [6] -2.220446e-16
print(fit)
#> Order-2 Gaussian trend filtering (native C++; dense)
#> 20 observations; 20 distinct locations
#> lambda converged status stationarity complementarity
#> Inf TRUE converged 1.110223e-16 0