# `opls` — Orthogonal PLS (OPLS) _Group_: **Core PLS** · _Registry tolerance_: `0.001` ## Description Orthogonal PLS (Trygg & Wold 2002) From the `pls4all.sklearn.OPLSRegression` docstring: > Orthogonal PLS regression (Trygg & Wold 2002). > **Registry note** — Bioconductor `ropls::opls` is the external OPLS reference; convergence and orthogonal-component conventions may differ. ### Parameters | Name | Type | Default | Notes | |------|------|---------|-------| | `n_components` | `int` | `2` | Number of latent components extracted (k). | | `solver` | `str` | `'nipals'` | Inner algorithm: 'nipals', 'simpls', 'svd', 'kernel', 'orthogonal-scores', 'power', 'randomized-svd', 'wide-kernel'. | | `center_x` | `bool` | `True` | Subtract the column mean of X before fitting. | | `scale_x` | `bool` | `True` | Standardize X columns to unit variance before fitting. | | `center_y` | `bool` | `True` | Subtract the column mean of y before fitting. | | `scale_y` | `bool` | `False` | Standardize y columns to unit variance before fitting. | | `tol` | `float` | `1e-06` | Convergence tolerance for iterative solvers (NIPALS / power-iteration). | | `max_iter` | `int` | `500` | Maximum iterations for iterative solvers. | | `store_scores` | `bool` | `False` | If True, keep the latent score matrix (`x_scores_`) after fit. | ## Explanations ### Bibliographic source Trygg, J. & Wold, S. (2002). *Orthogonal projections to latent structures (O-PLS)*. Journal of Chemometrics 16(3), 119–128. ### Mathematical principle OPLS rotates the standard PLS latent space so that a single direction captures all $\mathbf{Y}$-correlated variation while the remaining components capture $\mathbf{Y}$-orthogonal structural variation in $\mathbf{X}$. The resulting decomposition $\mathbf{X} = \mathbf{t}_p\mathbf{p}_p^{\top} + \mathbf{T}_o\mathbf{P}_o^{\top} + \mathbf{E}$ separates the **predictive component** $\mathbf{t}_p$ from the orthogonal block $\mathbf{T}_o$, which absorbs spectroscopic baselines, scatter and other nuisance factors that confound interpretation of the predictive loading. Numerically OPLS proceeds by NIPALS-deflating $\mathbf{X}$ against directions orthogonal to $\mathbf{X}^{\top}\mathbf{y}$ before each new predictive component is extracted. Predictions are identical to those of a one-component PLS on the orthogonal-corrected $\mathbf{X}$; the value is in **the interpretation of the loadings**, not in better predictions per se. OPLS shines in metabolomics and process spectroscopy where the spectra carry strong systematic but non-predictive variation; in those settings the single-vector predictive loading is far easier to relate to biology / chemistry than a multi-component PLS loading matrix. ### Implementation `Algorithm.OPLS` + `Solver.NIPALS` + `Deflation.ORTHOGONAL`. Reference: Bioconductor `ropls::opls`. Note: orthogonal-component ordering and the criterion that stops orthogonal extraction differ between implementations — exact bit parity is not expected, but RMSE-rel parity within ~1e-3 is. MATLAB header (`bindings/matlab/+pls4all/OplsRegression.m`): ```text pls4all.OplsRegression — Orthogonal Partial Least Squares Regression model. Example: mdl = pls4all.OplsRegression(X, y, 5); yhat = predict(mdl, Xnew); ``` ### Usage Every pls4all binding tab dispatches into the same C kernel; the external libraries listed at the bottom of the page are the parity references registered in `benchmarks.parity_timing.registry`. Switch tabs to read the same fit in your language. The R package now ships drop-in-compatible facades for the CRAN `pls` package (`plsr`, `pcr`, `mvr`) and for the `mdatools::pls(x, y, ...)` matrix idiom — those tabs appear only on the methods that have a meaningful equivalence. **pls4all bindings** ::::{tab-set} :class: pls4all-bindings :::{tab-item} C ABI · libn4m :sync: c :class-label: lang-c ```c /* C ABI — libn4m (Model.fit path) */ n4m_context_t* ctx = n4m_context_create(); n4m_config_t* cfg = n4m_config_create(); n4m_config_set_algorithm(cfg, N4M_ALGORITHM_PLS_REGRESSION); n4m_config_set_solver (cfg, N4M_SOLVER_SIMPLS); n4m_config_set_n_components(cfg, 4); n4m_model_t* mdl = NULL; n4m_model_fit(ctx, cfg, &x_view, &y_view, &mdl); n4m_model_predict(ctx, mdl, &x_test_view, &y_hat_view); n4m_model_destroy(mdl); n4m_config_destroy(cfg); n4m_context_destroy(ctx); ``` ::: :::{tab-item} Python · pls4all (raw) :sync: python-raw :class-label: lang-python ```python import pls4all from pls4all import Algorithm, Solver with pls4all.Context() as ctx, pls4all.Config() as cfg: cfg.algorithm = Algorithm.PLS_REGRESSION cfg.solver = Solver.SIMPLS cfg.n_components = 4 with pls4all.Model.fit(ctx, cfg, X, y) as mdl: y_hat = mdl.predict(X_test) ``` ::: :::{tab-item} Python · pls4all.sklearn :sync: python-sklearn :class-label: lang-python ```python from pls4all.sklearn import OPLSRegression mdl = OPLSRegression(n_components=2, solver='nipals', center_x=True, scale_x=True, center_y=True, scale_y=False, tol=1e-06, max_iter=500, store_scores=False) mdl.fit(X, y) y_hat = mdl.predict(X_test) ``` ::: :::{tab-item} R · pls4all_method() :sync: r-dispatcher :class-label: lang-r ```r library(pls4all) # Unified low-level dispatcher (May 2026 R cleanup): res <- pls4all_method("opls", X, y, n_components = 4L) # res is a named list with MethodResult arrays/scalars. # selected_indices / top_k_intervals are 1-based. ``` ::: :::{tab-item} MATLAB · pls4all (MEX) :sync: matlab-mex :class-label: lang-matlab ```matlab res = pls4all.opls(X, y, 4); % see header of bindings/matlab/+pls4all/opls.m for full % parameter surface: % [coefs, x_mean, y_mean, predictions] = opls(X, Y, n_components) yhat = predict(res, Xtest); ``` ::: :::{tab-item} MATLAB · pls4all (classdef) :sync: matlab-classdef :class-label: lang-matlab ```matlab mdl = pls4all.fit("opls", X, y, "NumComponents", 4); yhat = predict(mdl, Xtest); ``` ::: :::: **Registry parity references** 📐 :::{card} :class-card: external-refs - 📐 **`ref.r_ropls`** (R · r) — `ropls` Bioc · relaxed (rmse_rel ≤ 1e-03) — Bioconductor `ropls::opls` — OPLS reference. Permutations and plotting are disabled in benchmark timing; ropls still requires crossvalI >= 1 for a finite Q2 path. ::: ### Benchmarks Adaptive wall-clock per cell measured against [`full_matrix.csv`](../benchmarks/overview.md). Only backends that implement this method are listed; libraries without the method are omitted. **Verdict**  ·  ✓ ref / ≈ ref / ~ shape mark a reference-gate pass at strict / relaxed / qualitative tolerance  ·  ✓ bind = pls4all binding agrees with the C++ baseline  ·  ✗ divergent  ·  ⚠ error  ·  — not run. The fastest backend per column is marked 🏆. **Reference gate**: relaxed — known algorithmic drift between pls4all and the external reference (`rmse_rel_tol ≤ 1e-03`). Rows tagged with **📐** are the canonical parity references for this method (declared in [`parity_timing.registry`](../benchmarks/methodology.md)). C++ and external rows show reference parity; pls4all language bindings show binding parity against the C++ backend. Hover the icon for role and tolerance band. ::::{tab-set} :class: parity-tabs :::{tab-item} 1 thread :sync: threads-1
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×50 (ms)250×50 (ms)500×50 (ms)500×500 (ms)500×2500 (ms)2500×50 (ms)2500×500 (ms)2500×2500 (ms)10000×50 (ms)10000×500 (ms)
C++ native · libn4m
pls4all.cpp.blas≈ +5e-152.79 ms🏆2.47 ms20.1 ms169.3 ms1.92 ms2.58 ms6.51 ms🏆71.3 ms🏆434.4 ms36.1 ms413.0 ms🏆2.3 s148.5 ms1.8 s🏆
pls4all.cpp.blas+omp≈ +5e-153.29 ms2.51 ms15.7 ms🏆158.4 ms🏆2.01 ms2.73 ms7.33 ms75.0 ms433.1 ms🏆34.7 ms427.0 ms2.2 s151.5 ms1.8 s
pls4all.cpp.omp≈ +5e-153.16 ms2.31 ms18.1 ms166.0 ms1.90 ms3.06 ms6.86 ms72.7 ms446.7 ms33.7 ms🏆430.8 ms2.3 s144.3 ms🏆1.9 s
pls4all.cpp.ref≈ +5e-153.01 ms2.26 ms🏆18.6 ms162.0 ms1.88 ms🏆2.72 ms7.46 ms75.1 ms456.7 ms36.4 ms414.1 ms2.2 s🏆151.6 ms1.8 s
Python · pls4all
pls4all.python✓ bind2.82 ms2.16 ms2.50 ms🏆
pls4all.sklearn✓ bind3.21 ms3.97 ms2.78 ms
R · pls4all
pls4all.R✓ 1e-1311.3 ms6.83 ms7.92 ms
pls4all.R.formula✓ 1e-1319.8 ms9.63 ms8.97 ms
pls4all.R.mdatools✓ 1e-1319.3 ms9.15 ms9.43 ms
pls4all.R.pls✓ 1e-1318.0 ms9.77 ms8.58 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+005.58 ms3.26 ms5.85 ms
pls4all.matlab.classdef✗ +9e+005.68 ms3.69 ms4.53 ms
R · external
📐ref.r_ropls≈ ref21.7 ms
::: :::{tab-item} 3 threads :sync: threads-3
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×50 (ms)250×50 (ms)500×50 (ms)500×500 (ms)500×2500 (ms)2500×50 (ms)2500×500 (ms)2500×2500 (ms)10000×50 (ms)10000×500 (ms)
C++ native · libn4m
pls4all.cpp.blas≈ ref 5e-152.99 ms
pls4all.cpp.blas+omp≈ ref 5e-151.85 ms🏆
pls4all.cpp.omp≈ ref 5e-152.86 ms
pls4all.cpp.ref≈ ref 5e-153.39 ms
Python · pls4all
pls4all.python✓ 2e-142.60 ms
pls4all.sklearn✓ 2e-142.37 ms
R · pls4all
pls4all.R✓ bind6.27 ms
pls4all.R.formula✓ bind9.34 ms
pls4all.R.mdatools✓ bind8.89 ms
pls4all.R.pls✓ bind7.78 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+003.38 ms
pls4all.matlab.classdef✗ +9e+004.94 ms
R · external
📐ref.r_roplssource22.0 ms
::: :::{tab-item} 10 threads :sync: threads-10
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×50 (ms)250×50 (ms)500×50 (ms)500×500 (ms)500×2500 (ms)2500×50 (ms)2500×500 (ms)2500×2500 (ms)10000×50 (ms)10000×500 (ms)
C++ native · libn4m
pls4all.cpp.blas≈ ref 5e-151.81 ms
pls4all.cpp.blas+omp≈ ref 5e-151.80 ms
pls4all.cpp.omp≈ ref 5e-151.80 ms
pls4all.cpp.ref≈ ref 5e-151.75 ms🏆
Python · pls4all
pls4all.python✓ 2e-141.83 ms
pls4all.sklearn✓ 2e-141.95 ms
R · pls4all
pls4all.R✓ bind4.96 ms
pls4all.R.formula✓ bind6.77 ms
pls4all.R.mdatools✓ bind6.29 ms
pls4all.R.pls✓ bind6.65 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+003.05 ms
pls4all.matlab.classdef✗ +9e+003.27 ms
R · external
📐ref.r_roplssource17.3 ms
::: :::: --- _See also_: [benchmark overview](../benchmarks/overview.md) · [methods index](index.md) · [interactive dashboard](../landing/dashboard.md)