Predict from Projection Trend Filtering
Source:R/projection_trend_filtering.R, R/projection_trend_filtering_cv.R
predict.projection.trend.filtering.fit.RdPredict from Projection Trend Filtering
Usage
# S3 method for class 'projection.trend.filtering.fit'
predict(
object,
newdata = NULL,
offset = NULL,
type = c("response", "link", "terms"),
allow.unconverged = FALSE,
...
)
# S3 method for class 'projection.trend.filtering.fit'
fitted(object, ...)
# S3 method for class 'projection.trend.filtering.fit'
residuals(object, ...)
# S3 method for class 'projection.trend.filtering.fit'
print(x, ...)
# S3 method for class 'projection.trend.filtering.fit'
summary(object, ...)
# S3 method for class 'projection.trend.filtering.cv'
predict(object, newdata = NULL, ...)Arguments
- object
A
projection.trend.filtering.fitor a completedprojection.trend.filtering.cv.- newdata
Predictor matrix or numeric data frame; defaults to training rows. Named columns are aligned to training names when both are supplied.
- offset
Known offset, required for new rows if used in fitting.
- type
"response","link", or"terms". Terms exclude the common intercept and offset, which are returned as attributes.- allow.unconverged
Explicitly allow predictions from a failed fit.
- ...
Reserved for generic compatibility.
- x
A fitted projection trend-filtering model.
Value
A vector, or a matrix for type="terms". The outside.range
attribute is a row-by-component matrix identifying constant-boundary
extension of each univariate curve.
Examples
X <- matrix(seq(0, 1, length.out = 12), ncol = 1)
y <- sin(3*X[,1])
fit <- fit.projection.trend.filtering(X, y, lambda=0.001,
direction.search="fixed")
predict(fit, matrix(c(0.2, 0.8), ncol=1))
#> [1] 0.5933003 0.6899698
#> attr(,"outside.range")
#> term1
#> [1,] FALSE
#> [2,] FALSE
head(fitted(fit))
#> [1] -0.03245868 0.28876665 0.54867629 0.74727024 0.88454850 0.96051107
head(residuals(fit))
#> [1] 0.032458677 -0.019407744 -0.029869560 -0.017366022 0.002498487
#> [6] 0.018107930
print(fit)
#> Order-2 projection trend filtering (gaussian)
#> Components: 1 Fit: converged Search: fixed_directions
#> Mean-loss objective: 0.0002394855
summary(fit)
#> $family
#> [1] "gaussian"
#>
#> $nterms
#> [1] 1
#>
#> $lambda
#> [1] 0.001
#>
#> $curve.ridge
#> [1] 0.001
#>
#> $checks
#> $checks$objective
#> [1] 0.0002394855
#>
#> $checks$loss
#> [1] 0.0001859381
#>
#> $checks$l1
#> [1] 6.667024e-11
#>
#> $checks$ridge
#> [1] 5.354732e-05
#>
#> $checks$stationarity
#> [1] 2.482937e-11
#>
#> $checks$complementarity
#> [1] 6.291535e-11
#>
#> $checks$dual.feasibility
#> [1] 0
#>
#> $checks$converged
#> [1] TRUE
#>
#>
#> $status
#> [1] "converged"
#>
#> $search.status
#> [1] "fixed_directions"
#>
#> $solver.calls
#> [1] 1
#>
#> $directions
#> [,1]
#> [1,] 1
#>
#> attr(,"class")
#> [1] "list"
cv <- cv.projection.trend.filtering(X, y, foldid=rep(1:3, 4),
lambda.grid=Inf, nterms.grid=1, direction.search="fixed")
predict(cv, X[1:2, , drop=FALSE])
#> [1] -0.03245868 0.28876665
#> attr(,"outside.range")
#> term1
#> [1,] FALSE
#> [2,] FALSE