R/RcppExports.R

Defines functions estimate_all_pls estimate_basic_pls get_pls_weights

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' @title Computes the weights for pls regressions
#' @description
#' This is an internal function that computes the wights required for obtaining
#' each vector of pls weights. Implementation is done in C++ for improved performance.
#' @param X a numeric matrix of spectral data.
#' @param Y a matrix of one column with the response variable.
#' @param algorithm a string indicating what method to use. All available options
#' are: \code{'pls_modified'} (default), \code{'pls_standard'}, \code{'pls_nwp'},
#' \code{'xls_modified'}, \code{'xls_standard'}, and \code{'xls_nwp'}.
#' In particular, you can either select partial least squares (pls) or extended
#' partial least squares, with either modified weights (using correlation),
#' standard weights (using covariance) or nwp (i.e. as implemented in NIRWise PLUS software).
#' The NIRWise PLUS implementation calculates the weights also via correlation,
#' but also adjusts the weights and scores according to a slope correction.
#' @param xls_min_w an integer indicating the minimum window size for the "xls"
#' method. Only used if \code{algorithm} contains \code{'xls'}. Default is 3.
#' @param xls_max_w an integer indicating the maximum window size for the "xls"
#' method. Only used if \code{algorithm} contains \code{'xls'}. Default is 15.
#' @author Leonardo Ramirez-Lopez and Claudio Orellano
#' @return a `matrix` of one column containing the weights.
#' @useDynLib proximetricsR
#' @noRd
#' @keywords internal
get_pls_weights <- function(X, Y, algorithm = "pls_modified", xls_min_w = 3L, xls_max_w = 15L) {
    .Call('_proximetricsR_get_pls_weights', PACKAGE = 'proximetricsR', X, Y, algorithm, xls_min_w, xls_max_w)
}

#' @title Fast regression method computation
#' @description This function computes the basic elements of a partial least squares (pls)
#' regression model for either the partial least squares or the extended partial
#' least squares methods, where each regression method has three subtypes:
#' \code{"modified"}, \code{"standard"} and \code{"nwp"}. For more details on
#' these types, see \code{\link{fit_constructors}}.
#'
#' The least amount of data is saved to compute predictions, which makes this
#' function optimal to use during cross-validation evalutations.
#' @usage
#' estimate_basic_pls(X, Y, method)
#' @param X a numeric matrix of spectral data.
#' @param Y a matrix of one column with the response variable.
#' @param method a list of class \code{fit_constructor} specifying the fit method,
#' as specified with the \code{\link{fit_constructors}} functions.
#' @return a list with the following elements:
#' \itemize{
#'         \item{\code{coefficients}:} { The matrix of regression coefficients.
#'         Can be used to predict reference values for new spectral observations.}
#'         \item{\code{intercept}:} { The intercept of the models. Note that it
#'         is constant for all components and defined by the mean of input
#'         \code{Y}.}
#'         \item{\code{x_means}:} { The mean of each column of input \code{X}.}
#'         }
#' @details
#' Computes one of "pls" and "xls" regression model for the given \code{method}.
#' @seealso \code{\link{fit_constructors}}, \code{\link{calibrate}}
#' @author Leonardo Ramirez-Lopez and Claudio Orellano
#' @useDynLib proximetricsR
#' @noRd
#' @keywords internal
estimate_basic_pls <- function(X, Y, method) {
    .Call('_proximetricsR_estimate_basic_pls', PACKAGE = 'proximetricsR', X, Y, method)
}

#' @title Compute all information of a given regression method.
#' @description This function computes all important information related to a
#' partial least squares (pls) or an extended partial least squares (xls)
#' regression model. Each regression method has three subtypes:
#' \code{"modified"}, \code{"standard"} and \code{"nwp"}. For more details on
#' these types, see \code{\link{fit_constructors}}.
#' @usage
#' estimate_all_pls(X, Y, method)
#' @param X a numeric matrix of spectral data.
#' @param Y a matrix of one column with the response variable.
#' @param method a list of class \code{fit_constructor} specifying the regression method,
#' as specified with the \code{\link{fit_constructors}} functions.
#' @return a list with the following elements:
#' \itemize{
#'         \item{\code{intercept}:} { The intercept of the models. Note that it
#'         is constant for all components and defined by the mean of input
#'         \code{Y}.}
#'         \item{\code{x_means}:} { The mean of columns of input \code{X}.}
#'         \item{\code{projection_m}:} { The projection matrix. Can be used
#'         to project new spectral observations onto the score space.}
#'         \item{\code{coefficients}:} { The matrix of regression coefficients.
#'         These coefficients can be used to predict reference values from new
#'         spectral observations.}
#'         \item{\code{n_observations}:} {The number of observations used for regression.}
#'         \item{\code{x_residuals}:} { The spectral residuals obtained for each component.}
#'         \item{\code{weights}:} { The matrix of weights.}
#'         \item{\code{scores}:} { The matrix of scores.}
#'         \item{\code{sd_scores}:} { The matrix containing the standard deviations
#'         of each column of the scores.}
#'         \item{\code{scaled_scores}:} { The matrix of scaled scores.}
#'         \item{\code{y_loadings}:} { The matrix of loadings for Y.}
#'         \item{\code{x_loadings}:} { The matrix of loadings for X.}
#'         \item{\code{fitted_y}:} { The fitted values for the response variable.}
#'         \item{\code{cal_error}:} { The error statistics estimated for each component.}
#'         \item{\code{y_quantiles}:} { The quantiles of input \code{Y}.}
#'         \item{\code{explained_variance}:} { The variance of input \code{X}.}
#'         }
#' @details
#' Reproduces both, the "pls" and "xls" regression methods in BUCHI NIRWise PLUS.
#' @seealso \code{\link{fit_constructors}}, \code{\link{calibrate}}
#' @author Leonardo Ramirez-Lopez and Claudio Orellano
#' @useDynLib proximetricsR
#' @noRd
#' @keywords internal
estimate_all_pls <- function(X, Y, method) {
    .Call('_proximetricsR_estimate_all_pls', PACKAGE = 'proximetricsR', X, Y, method)
}

Try the proximetricsR package in your browser

Any scripts or data that you put into this service are public.

proximetricsR documentation built on Sept. 4, 2026, 5:08 p.m.