Types
NCPLS relies on two main container types in the StatsAPI.fit and StatsAPI.predict workflow. NCPLSModel stores the fitting specification: preprocessing options, the number of extracted components, and the switches that control the multilinear loading-weight branch. NCPLSFit is the full fitted model returned by fit; it contains regression coefficients, predictor scores, multilinear weight information, preprocessing statistics, and the labels or axis metadata retained from model fitting.
A third container, NCPLSFitLight, stores only the subset of fitted-model information needed for fast internal prediction during cross-validation. It is mainly an internal optimization and is usually not accessed directly.
The package provides getters for quantities that are commonly useful in downstream work. For fitted models, the most important ones are coef, fitted, residuals, xscores, predictoraxes, responselabels, samplelabels, sampleclasses, xmean, xstd, and ymean. NCPLSModel does not currently have a separate getter layer; its options are accessed directly as fields, for example model.multilinear, model.orthogonalize_mode_weights, or model.ncomponents.
Two stored label vectors are easy to confuse:
sampleclasseslives on the sample axis and stores one label per training sample,responselabelslives on the response axis and stores one label per response column.
These vectors interact only when NCPLS tries to infer a class-response block from a custom response matrix. If the unique sample classes can be matched consistently to a one-hot sub-block of the responses, classification helpers use that sub-block. If not, sampleclasses(mf) remains sample-level metadata for grouping and visualization.
As with the CPPLS documentation, the purpose of this page is to describe the stored containers and the most useful accessors. The modeling choices controlled through fit are discussed on the Fit page, and the downstream interpretation of predictions is discussed on Projection and Prediction.
NCPLSModel
NCPLSModel is the user-facing model specification. It stores:
- the number of latent components to extract,
- predictor preprocessing choices (
center_X,scale_X), - primary-response centering (
center_Yprim), - whether predictor-side weights stay unfolded or are compressed to rank-1 multilinear tensors (
multilinear), - whether multilinear mode vectors are orthogonalized across components (
orthogonalize_mode_weights), - and the PARAFAC control parameters used in the multilinear branch.
The default NCPLSModel() uses multilinear=true, so genuinely multiway predictors are handled through the multilinear weight representation unless you request the unfolded comparison branch explicitly.
NCPLS.NCPLSModel — Type
NCPLSModelModel specification passed to fit. An NCPLSModel stores the centering and scaling options for X, the centering option for Yprim, the number of extracted components, and the settings that control the multilinear loading-weight branch.
PredictorAxis
PredictorAxis stores metadata for one non-sample predictor mode. It is useful when your predictor tensor has meaningful coordinates such as time, wavelength, or m/z values, and you want those coordinates retained on the fitted model for downstream plots or inspection.
Provide one PredictorAxis per non-sample predictor mode through the predictoraxes keyword in fit. The stored tuple can then be retrieved with predictoraxes.
NCPLS.PredictorAxis — Type
PredictorAxis(name, values; unit=nothing)
PredictorAxis(; name, values, unit=nothing)Store metadata for one non-sample predictor axis of a multiway NCPLS fit. name identifies the axis (for example "RT" or "m/z"), values stores the axis positions, and unit optionally stores the physical unit separately from the numeric values.
AbstractNCPLSFit
AbstractNCPLSFit is the common supertype of full and reduced fitted NCPLS models. The generic fitted-model accessors are defined at this level.
coef returns the regression coefficients for the final or requested number of components. These coefficients act on predictors after the fitted model's centering and optional scaling have been applied. xmean, xstd, and ymean expose the stored preprocessing statistics, and ncomponents returns the number of latent components retained in the fitted object.
NCPLS.AbstractNCPLSFit — Type
AbstractNCPLSFitAbstract supertype for fitted NCPLS models.
StatsAPI.coef — Method
coef(mf::AbstractNCPLSFit)
coef(mf::AbstractNCPLSFit, ncomps::Integer)Return the regression coefficients for the final or requested number of components. The returned tensor acts on preprocessed predictors, i.e. on X after the centering and optional scaling stored in the fitted model have been applied.
NCPLS.xmean — Method
xmean(mf::AbstractNCPLSFit)Return the predictor mean array for the fitted model.
NCPLS.xstd — Method
xstd(mf::AbstractNCPLSFit)Return the predictor standard deviation array for the fitted model.
NCPLS.ymean — Method
ymean(mf::AbstractNCPLSFit)Return the primary-response mean vector for the fitted model.
NCPLS.ncomponents — Method
ncomponents(mf::AbstractNCPLSFit)Return the number of latent components stored in the fitted NCPLS model.
NCPLSFit
NCPLSFit is the full fitted model returned by fit. In addition to the coefficient tensor, it stores predictor scores, loadings, projection objects, response residuals, and the multilinear diagnostics associated with each extracted component.
The most commonly used fitted-model getters are:
fittedfor fitted responses on the original response scale,residualsfor response residuals,xscoresfor latent predictor scores,responselabels,samplelabels, andsampleclassesfor stored labels,predictoraxesfor retained predictor-axis metadata.
For deeper inspection, the full stored fields remain accessible via dot notation. This is particularly useful for multilinear fits, where mf.W_modes, mf.W_multilinear_relerr, mf.W_multilinear_method, mf.W_multilinear_lambda, mf.W_multilinear_niter, and mf.W_multilinear_converged expose the component-wise PARAFAC approximation details.
NCPLS.NCPLSFit — Type
NCPLSFitFitted NCPLS model returned by fit. An NCPLSFit stores the regression and projection objects, component-wise scores and loadings, multilinear diagnostics, and the preprocessing statistics needed for prediction and inspection. For multilinear fits, the stored diagnostics include the PARAFAC approximation error, method, scaling, iteration count, and convergence flag for each extracted component.
StatsAPI.fitted — Method
fitted(mf::NCPLSFit)
fitted(mf::NCPLSFit, ncomps::Integer)Return the fitted response matrix for the final or requested number of components.
NCPLS.predictoraxes — Method
predictoraxes(mf::NCPLSFit)Return the stored metadata for the non-sample predictor axes of the fitted model.
StatsAPI.residuals — Method
residuals(mf::NCPLSFit)
residuals(mf::NCPLSFit, ncomps::Integer)Return the response residual matrix for the final or requested number of components.
NCPLS.responselabels — Method
responselabels(mf::NCPLSFit)Return the stored response labels for the fitted model, one label per response column.
NCPLS.sampleclasses — Method
sampleclasses(mf::NCPLSFit)Return the stored per-sample class labels, or nothing when no classes were supplied at fit time. These labels live on the sample axis and are stored exactly as supplied. When they match response labels and a one-hot class block in a custom response matrix, NCPLS also uses them to infer which response columns carry class scores.
NCPLS.samplelabels — Method
samplelabels(mf::NCPLSFit)Return the stored sample labels for the fitted model.
NCPLS.xscores — Method
xscores(mf::NCPLSFit)
xscores(mf::NCPLSFit, comp::Integer)
xscores(mf::NCPLSFit, comps::AbstractUnitRange{<:Integer})
xscores(mf::NCPLSFit, comps::AbstractVector{<:Integer})Return the predictor score matrix for the fitted model, or a subset of its columns.
NCPLSFitLight
NCPLSFitLight is a reduced fitted-model container used mainly in cross- validation, permutation testing, and nested resampling. It stores only what prediction needs: the coefficient tensor and the preprocessing statistics required to restore the predictor and response scales.
Most users will interact with it only indirectly through the resampling helpers.
NCPLS.NCPLSFitLight — Type
NCPLSFitLight{TB, TXStat, TYStat}Reduced fitted NCPLS model that retains only the information needed for prediction. This type is used mainly for efficient internal prediction during cross-validation.