% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fit_methods.R
\name{fit_methods}
\alias{fit_methods}
\alias{fit_pls}
\alias{fit_wapls}
\alias{fit_gpr}
\title{Local fitting method constructors}
\usage{
fit_pls(ncomp, method = c("pls", "mpls", "simpls"), 
        scale = FALSE, max_iter = 100L, tol = 1e-6)

fit_wapls(min_ncomp, max_ncomp, method = c("mpls", "pls", "simpls"),
          scale = FALSE, max_iter = 100L, tol = 1e-6)

fit_gpr(noise_variance = 0.001, center = TRUE, scale = TRUE)
}
\arguments{
\item{ncomp}{an integer indicating the number of PLS components to use
in local regressions when \code{fit_pls} is used.}

\item{min_ncomp}{an integer indicating the minimum number of PLS components
to use in local regressions when \code{fit_wapls} is used. See details.}

\item{max_ncomp}{an integer indicating the maximum number of PLS components
to use in local regressions when \code{fit_wapls} is used. See details.}

\item{method}{a character string indicating the PLS algorithm to use.
Options are:
\itemize{
\item{\code{'pls'}: standard PLS using covariance between X and Y for
weight computation (NIPALS algorithm).}
\item{\code{'mpls'}: modified PLS using correlation between X and Y for
weight computation (NIPALS algorithm). See Shenk and Westerhaus (1991).}
\item{\code{'simpls'}: SIMPLS algorithm (de Jong, 1993). Computationally
faster as it avoids iterative X deflation. Parameters \code{max_iter}
and \code{tol} are ignored when this method is used.}
}
Default is \code{'pls'} for \code{fit_pls} and \code{'mpls'} for
\code{fit_wapls}.}

\item{scale}{logical indicating whether predictors must be scaled.
Default is \code{FALSE} for PLS methods and \code{TRUE} for GPR.}

\item{max_iter}{an integer indicating the maximum number of iterations
for convergence in the NIPALS algorithm. Only used when
\code{method = 'pls'} or \code{method = 'mpls'}. Default is 100.}

\item{tol}{a numeric value indicating the convergence tolerance for
calculating scores in the NIPALS algorithm. Only used when
\code{method = 'pls'} or \code{method = 'mpls'}. Default is 1e-6.}

\item{noise_variance}{a numeric value indicating the variance of the noise
for Gaussian process local regressions (\code{fit_gpr}). Default is 0.001.}

\item{center}{logical indicating whether predictors should be centered
before fitting. Only used for \code{fit_gpr}. Default is \code{TRUE}.}
}
\value{
An object of class \code{c("fit_<method>", "fit_method")}
containing the specified parameters. This object is passed to
\code{\link{mbl}} to configure local model fitting.
}
\description{
\loadmathjax

These functions create configuration objects that specify how local
regression models are fitted within the \code{\link{mbl}} function.
}
\details{
These functions create configuration objects that are passed to
\code{\link{mbl}} to specify how local regression models are fitted.

There are three fitting methods available:

\subsection{Partial least squares (\code{fit_pls})}{
Uses orthogonal scores partial least squares regression. Three algorithm
variants are available:
\itemize{
\item{\strong{Standard PLS} (\code{method = 'pls'}): Uses the NIPALS
algorithm with covariance-based weights.}
\item{\strong{Modified PLS} (\code{method = 'mpls'}): Uses the NIPALS
algorithm with correlation-based weights. Proposed by Shenk and
Westerhaus (1991), this approach gives equal influence to all
predictors regardless of their variance scale.}
\item{\strong{SIMPLS} (\code{method = 'simpls'}): Uses the SIMPLS
algorithm (de Jong, 1993), which deflates the cross-product matrix
rather than X itself. This is computationally faster, especially for
wide matrices, and produces identical predictions to standard PLS.}
}
The only parameter to optimise is the number of PLS components
(\code{ncomp}).
}

\subsection{Weighted average PLS (\code{fit_wapls})}{
This method was developed by Shenk et al. (1997) and is used as the
regression method in the LOCAL algorithm. It fits multiple PLS models
using different numbers of components (from \code{min_ncomp} to
\code{max_ncomp}). The final prediction is a weighted average of
predictions from all models, where the weight for component \mjeqn{j}{j}
is:

\mjdeqn{w_{j} = \frac{1}{s_{1:j} \times g_{j}}}{w_j = 1/(s_{1:j} * g_j)}

where \mjeqn{s_{1:j}}{s_{1:j}} is the root mean square of the spectral
reconstruction error of the target observation(s) when \mjeqn{j}{j} PLS
components are used, and \mjeqn{g_{j}}{g_j} is the root mean square of
the squared regression coefficients for the \mjeqn{j}{j}th component.

The same algorithm variants (\code{'pls'}, \code{'mpls'}, \code{'simpls'})
are available. The default is \code{'mpls'} following the original LOCAL
implementation.
}

\subsection{Gaussian process regression (\code{fit_gpr})}{
Gaussian process regression is a non-parametric Bayesian method
characterised by a mean and covariance function. This implementation uses
a dot product covariance.

The prediction vector \mjeqn{A}{A} is computed from training data
(\mjeqn{X}{X}, \mjeqn{Y}{Y}) as:

\mjdeqn{A = (X X^{T} + \sigma^2 I)^{-1} Y}{A = (X X^T + sigma^2 I)^{-1} Y}

where \mjeqn{\sigma^2}{sigma^2} is the noise variance and \mjeqn{I}{I} is
the identity matrix. Prediction for a new observation
\mjeqn{x_{u}}{x_u} is:

\mjdeqn{\hat{y}_{u} = x_{u} X^{T} A}{hat y_u = x_u X^T A}

The only parameter is the noise variance (\code{noise_variance}).
}
}
\examples{
# PLS with 10 components using standard algorithm
fit_pls(ncomp = 10)

# PLS with modified algorithm (correlation-based weights)
fit_pls(ncomp = 10, method = "mpls")

# PLS with SIMPLS (faster, no iteration)
fit_pls(ncomp = 10, method = "simpls")

# Weighted average PLS (LOCAL-style)
fit_wapls(min_ncomp = 3, max_ncomp = 12)

# Weighted average PLS with SIMPLS
fit_wapls(min_ncomp = 3, max_ncomp = 15, method = "simpls")

# Gaussian process regression
fit_gpr()
fit_gpr(noise_variance = 0.01)

}
\references{
de Jong, S. (1993). SIMPLS: An alternative approach to partial least
squares regression. Chemometrics and Intelligent Laboratory Systems,
18(3), 251-263.

Rasmussen, C.E., Williams, C.K. (2006). Gaussian Processes for Machine
Learning. MIT Press.

Shenk, J.S., & Westerhaus, M.O. (1991). Populations structuring of near
infrared spectra and modified partial least squares regression. Crop
Science, 31(6), 1548-1555.

Shenk, J., Westerhaus, M., & Berzaghi, P. (1997). Investigation of a LOCAL
calibration procedure for near infrared instruments. Journal of Near
Infrared Spectroscopy, 5, 223-232.

Westerhaus, M. (2014). Eastern Analytical Symposium Award for outstanding
achievements in near infrared spectroscopy: my contributions to near
infrared spectroscopy. NIR news, 25(8), 16-20.
}
\seealso{
\code{\link{mbl}}
}
\author{
\href{https://orcid.org/0000-0002-5369-5120}{Leonardo Ramirez-Lopez}
}
