% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/methods.R
\name{predict.lgspline}
\alias{predict.lgspline}
\title{Predict Method for lgspline Objects}
\usage{
\method{predict}{lgspline}(
  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,
  ...
)
}
\arguments{
\item{object}{A fitted lgspline model object.}

\item{newdata}{Matrix or data.frame; new predictor values. Default NULL.}

\item{parallel}{Logical; use parallel processing (experimental).
Default FALSE.}

\item{cl}{Cluster object for parallel processing. Default NULL.}

\item{chunk_size}{Integer; chunk size for parallel processing. Default NULL.}

\item{num_chunks}{Integer; number of chunks. Default NULL.}

\item{rem_chunks}{Integer; remainder chunks. Default NULL.}

\item{B_predict}{List; per-partition coefficient list for prediction, e.g.
from \code{\link{generate_posterior}}. Default NULL uses
\code{object$B}.}

\item{take_first_derivatives}{Logical; compute first derivatives.
Default FALSE.}

\item{take_second_derivatives}{Logical; compute second derivatives.
Default FALSE.}

\item{expansions_only}{Logical; return basis expansion matrix only.
Default FALSE.}

\item{new_predictors}{Matrix or data.frame; overrides \code{newdata}.}

\item{...}{Additional arguments passed to the internal predict method.}
}
\value{
A numeric vector of predictions, or a list when derivatives or
  interval summaries are requested:
\describe{
  \item{preds}{Numeric vector of predictions when derivatives are requested.}
  \item{fit}{Numeric vector of predictions when \code{se.fit = TRUE} and no
        derivatives are requested.}
  \item{first_deriv}{Numeric vector or named list of first derivatives (if
        requested).}
  \item{second_deriv}{Numeric vector or named list of second derivatives (if
        requested).}
  \item{se.fit}{Pointwise standard errors on the link scale (if requested).}
  \item{lower}{Pointwise lower interval bound (if requested).}
  \item{upper}{Pointwise upper interval bound (if requested).}
  \item{cv}{Critical value returned when \code{se.fit = TRUE} without
        derivative requests.}
}
If \code{expansions_only = TRUE}, returns a list of basis expansions.
}
\description{
Generates predictions, derivatives, and basis expansions from a fitted
lgspline model. Wrapper for the internal predict closure stored in the
object.
}
\details{
\code{new_predictors} takes priority over \code{newdata} when both are
supplied. When both are NULL, the training data is used.

Fitted values are also accessible directly as \code{model_fit$ytilde} or
via \code{model_fit$predict()}.

The parallel processing feature is experimental.

Additional arguments passed through \code{...} include \code{se.fit}
and \code{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.
}
\examples{

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)

}
\seealso{
\code{\link{lgspline}}, \code{\link{plot.lgspline}}
}
