| predict.lgspline | R Documentation |
Generates predictions, derivatives, and basis expansions from a fitted lgspline model. Wrapper for the internal predict closure stored in the object.
## S3 method for class 'lgspline'
predict(
object,
newdata = NULL,
parallel = FALSE,
cl = NULL,
chunk_size = NULL,
num_chunks = NULL,
rem_chunks = NULL,
B_predict = NULL,
take_first_derivatives = FALSE,
take_second_derivatives = FALSE,
expansions_only = FALSE,
new_predictors = NULL,
...
)
object |
A fitted lgspline model object. |
newdata |
Matrix or data.frame; new predictor values. Default NULL. |
parallel |
Logical; use parallel processing (experimental). Default FALSE. |
cl |
Cluster object for parallel processing. Default NULL. |
chunk_size |
Integer; chunk size for parallel processing. Default NULL. |
num_chunks |
Integer; number of chunks. Default NULL. |
rem_chunks |
Integer; remainder chunks. Default NULL. |
B_predict |
List; per-partition coefficient list for prediction, e.g.
from |
take_first_derivatives |
Logical; compute first derivatives. Default FALSE. |
take_second_derivatives |
Logical; compute second derivatives. Default FALSE. |
expansions_only |
Logical; return basis expansion matrix only. Default FALSE. |
new_predictors |
Matrix or data.frame; overrides |
... |
Additional arguments passed to the internal predict method. |
new_predictors takes priority over newdata when both are
supplied. When both are NULL, the training data is used.
Fitted values are also accessible directly as model_fit$ytilde or
via model_fit$predict().
The parallel processing feature is experimental.
Additional arguments passed through ... include se.fit
and cv for pointwise interval summaries.
Predictor input should use the original predictor columns. Named extra columns are dropped when they can be identified as irrelevant to the fitted expansions.
A numeric vector of predictions, or a list when derivatives or interval summaries are requested:
Numeric vector of predictions when derivatives are requested.
Numeric vector of predictions when se.fit = TRUE and no
derivatives are requested.
Numeric vector or named list of first derivatives (if requested).
Numeric vector or named list of second derivatives (if requested).
Pointwise standard errors on the link scale (if requested).
Pointwise lower interval bound (if requested).
Pointwise upper interval bound (if requested).
Critical value returned when se.fit = TRUE without
derivative requests.
If expansions_only = TRUE, returns a list of basis expansions.
lgspline, plot.lgspline
set.seed(1234)
t <- runif(1000, -10, 10)
y <- 2*sin(t) + -0.06*t^2 + rnorm(length(t))
model_fit <- lgspline(t, y)
newdata <- matrix(sort(rnorm(10000)), ncol = 1)
preds <- predict(model_fit, newdata)
deriv1_res <- predict(model_fit, newdata, take_first_derivatives = TRUE)
deriv2_res <- predict(model_fit, newdata, take_second_derivatives = TRUE)
oldpar <- par(no.readonly = TRUE)
layout(matrix(c(1,1,2,2,3,3), byrow = TRUE, ncol = 2))
plot(newdata[,1], preds, main = 'Fitted Function',
xlab = 't', ylab = "f(t)", type = 'l')
plot(newdata[,1], deriv1_res$first_deriv, main = 'First Derivative',
xlab = 't', ylab = "f'(t)", type = 'l')
plot(newdata[,1], deriv2_res$second_deriv, main = 'Second Derivative',
xlab = 't', ylab = "f''(t)", type = 'l')
par(oldpar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.