# `approximate_press` — Approximate PRESS (leave-one-out by hat-matrix) _Group_: **Diagnostic** · _Registry tolerance_: `1e-10` ## Description Approximate-PRESS component selection (§29) > **Registry note** — R `pls::plsr(validation='LOO', method='simpls', scale=FALSE)$validation$PRESS`. Default pls4all path runs true LOO PRESS over the same SIMPLS kernel and matches R bit-for-bit; `cfg.approximate_press_legacy = 1` falls back to the pre-0.97.4 Eastment-Krzanowski training-residual approximation. ### Parameters | Name | Type | Default | Notes | |------|------|---------|-------| | `max_components` | `int` | `6` | registry benchmark cell value | ## Explanations ### Bibliographic source Allen, D. M. (1974). *The relationship between variable selection and data augmentation and a method for prediction*. Technometrics 16(1), 125–127. ### Mathematical principle Exact leave-one-out cross-validation requires $n$ refits and costs $O(n^2 p k)$. The approximate PRESS uses the hat-matrix shortcut: the leave-one-out residual for sample $i$ is approximately $r_i^{(-i)} \approx r_i / (1 - h_{ii})$, where $h_{ii}$ is the diagonal of the hat matrix $\mathbf{H} = \mathbf{T}(\mathbf{T}^{\top}\mathbf{T})^{-1}\mathbf{T}^{\top}$. Total PRESS is $\sum_i (r_i^{(-i)})^2$, computed in $O(n p k)$ from a single fit. The approximation is exact for OLS and tight for PLS as long as no single $h_{ii}$ approaches 1 (a high-leverage outlier). Use exact LOO when the approximate PRESS diverges from the cross-validated RMSEP by more than a few percent. Drives the one-SE rule for selecting the component count $k$. ### Implementation `n4m_approximate_press_compute`. Returns a length-$(k_{\max}+1)$ vector indexed by component count. MATLAB header (`bindings/matlab/+pls4all/approximate_press.m`): ```text pls4all.approximate_press PRESS-curve component selection. res = pls4all.approximate_press(X, Y, max_components) For each k ∈ {1, …, max_components}, fits SIMPLS and approximates PRESS via leverage-inflated in-sample residuals. Returns: ``` ### 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 */ n4m_context_t* ctx = n4m_context_create(); n4m_config_t* cfg = n4m_config_create(); n4m_method_result_t* res = NULL; n4m_approximate_press_compute(ctx, cfg, &x_view, &y_view, /* hyperparams */, &res); /* … read coefficients / mask / scores via */ /* n4m_method_result_get_double_matrix / vector / scalar … */ n4m_method_result_destroy(res); 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._methods import approximate_press_compute with pls4all.Context() as ctx, pls4all.Config() as cfg: res = approximate_press_compute(ctx, cfg, X, y) # then: res.matrix("predictions"), res.matrix("coefficients"), # res.vector("mask"), res.scalar("intercept"), … ``` ::: :::{tab-item} Python · pls4all.sklearn :sync: python-sklearn :class-label: lang-python ```python from pls4all.sklearn import approximate_press result = approximate_press(X, y, n_components=2) ``` ::: :::{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("approximate_press", X, y, n_components = 2L, params = list(max_components = 6L)) # 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.approximate_press(X, y, 2); % see header of bindings/matlab/+pls4all/approximate_press.m for full % parameter surface: % res = approximate_press(X, Y, max_components) yhat = predict(res, Xtest); ``` ::: :::{tab-item} MATLAB · pls4all (classdef) :sync: matlab-classdef :class-label: lang-matlab _No idiomatic classdef wrapper — invoke `pls4all.fit("approximate_press", X, y, …)` directly from the unified MEX factory._ ::: :::: **Registry parity references** 📐 :::{card} :class-card: external-refs - 📐 **`ref.r_pls`** (R · r) — `pls` 2.8.5 · strict (rmse_rel ≤ 1e-10) — R `pls::plsr(validation='LOO', method='simpls', scale=FALSE)$validation$PRESS`. Default pls4all path runs true LOO PRESS over the same SIMPLS kernel and matches R bit-for-bit; `cfg.approximate_press_legacy = 1` falls back to the pre-0.97.4 Eastment-Krzanowski training-residual approximation. ::: ### 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**: strict — numeric equivalence (`rmse_rel_tol ≤ 1e-10`). 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×30 (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≈ +6e-1518.1 ms15.5 ms173.9 ms1.2 s🏆29.1 ms64.1 ms349.8 ms🏆6.3 s🏆55.2 s🏆11.2 s532.3 s🏆363.6 s
pls4all.cpp.blas+omp≈ +6e-1518.4 ms15.1 ms🏆190.2 ms1.3 s30.8 ms64.3 ms402.4 ms6.5 s56.5 s11.2 s538.4 s368.9 s
pls4all.cpp.omp≈ +6e-1520.6 ms16.3 ms171.8 ms1.4 s30.0 ms72.0 ms443.5 ms6.7 s58.8 s13.0 s547.6 s378.1 s
pls4all.cpp.ref≈ +6e-1517.5 ms16.0 ms170.6 ms🏆1.3 s29.8 ms63.9 ms381.4 ms6.5 s55.7 s11.2 s🏆537.0 s350.4 s🏆
Python · pls4all
pls4all.python✓ bind17.3 ms29.2 ms63.9 ms
pls4all.sklearn✓ bind17.3 ms🏆28.7 ms🏆61.9 ms🏆
R · pls4all
pls4all.R✗ +2e+0214.4 ms4.33 ms9.19 ms
pls4all.R.formula✗ +2e+0219.2 ms5.34 ms8.89 ms
pls4all.R.mdatools✗ +2e+0219.7 ms6.38 ms8.96 ms
pls4all.R.pls✗ +2e+0221.1 ms5.57 ms9.96 ms
MATLAB · pls4all
pls4all.matlab✗ +5e+0121.6 ms31.7 ms72.4 ms
pls4all.matlab.classdef✗ +5e+0122.0 ms29.8 ms70.5 ms
R · external
📐ref.r_plssource42.6 ms85.7 ms124.9 ms
::: :::{tab-item} 3 threads :sync: threads-3
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×30 (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 2e-1525.9 ms
pls4all.cpp.blas+omp✓ ref 2e-1525.9 ms
pls4all.cpp.omp✓ ref 2e-1528.5 ms
pls4all.cpp.ref✓ ref 2e-1526.3 ms
Python · pls4all
pls4all.python✓ bind25.9 ms
pls4all.sklearn✓ bind25.8 ms🏆
R · pls4all
pls4all.R✗ +4e+013.50 ms
pls4all.R.formula✗ +4e+015.59 ms
pls4all.R.mdatools✗ +4e+015.62 ms
pls4all.R.pls✗ +4e+014.87 ms
MATLAB · pls4all
pls4all.matlab✗ +5e+0126.1 ms
pls4all.matlab.classdef✗ +5e+0126.7 ms
R · external
📐ref.r_plssource87.8 ms
::: :::{tab-item} 10 threads :sync: threads-10
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×30 (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 2e-1524.6 ms
pls4all.cpp.blas+omp✓ ref 2e-1524.7 ms
pls4all.cpp.omp✓ ref 2e-1526.7 ms
pls4all.cpp.ref✓ ref 2e-1525.0 ms
Python · pls4all
pls4all.python✓ bind24.6 ms🏆
pls4all.sklearn✓ bind25.5 ms
R · pls4all
pls4all.R✗ +4e+013.10 ms
pls4all.R.formula✗ +4e+013.71 ms
pls4all.R.mdatools✗ +4e+013.82 ms
pls4all.R.pls✗ +4e+014.03 ms
MATLAB · pls4all
pls4all.matlab✗ +5e+0125.1 ms
pls4all.matlab.classdef✗ +5e+0125.6 ms
R · external
📐ref.r_plssource71.3 ms
::: :::: --- _See also_: [benchmark overview](../benchmarks/overview.md) · [methods index](index.md) · [interactive dashboard](../landing/dashboard.md)