# `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
| Backend | Parity | 50×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-15 | 18.1 ms | 15.5 ms | 173.9 ms | 1.2 s🏆 | 29.1 ms | 64.1 ms | 349.8 ms🏆 | 6.3 s🏆 | 55.2 s🏆 | 11.2 s | 532.3 s🏆 | — | 363.6 s | — |
pls4all.cpp.blas+omp | ≈ +6e-15 | 18.4 ms | 15.1 ms🏆 | 190.2 ms | 1.3 s | 30.8 ms | 64.3 ms | 402.4 ms | 6.5 s | 56.5 s | 11.2 s | 538.4 s | — | 368.9 s | — |
pls4all.cpp.omp | ≈ +6e-15 | 20.6 ms | 16.3 ms | 171.8 ms | 1.4 s | 30.0 ms | 72.0 ms | 443.5 ms | 6.7 s | 58.8 s | 13.0 s | 547.6 s | — | 378.1 s | — |
pls4all.cpp.ref | ≈ +6e-15 | 17.5 ms | 16.0 ms | 170.6 ms🏆 | 1.3 s | 29.8 ms | 63.9 ms | 381.4 ms | 6.5 s | 55.7 s | 11.2 s🏆 | 537.0 s | — | 350.4 s🏆 | — |
| Python · pls4all |
pls4all.python | ✓ bind | 17.3 ms | — | — | — | 29.2 ms | 63.9 ms | — | — | — | — | — | — | — | — |
pls4all.sklearn | ✓ bind | 17.3 ms🏆 | — | — | — | 28.7 ms🏆 | 61.9 ms🏆 | — | — | — | — | — | — | — | — |
| R · pls4all |
pls4all.R | ✗ +2e+02 | 14.4 ms | — | — | — | 4.33 ms | 9.19 ms | — | — | — | — | — | — | — | — |
pls4all.R.formula | ✗ +2e+02 | 19.2 ms | — | — | — | 5.34 ms | 8.89 ms | — | — | — | — | — | — | — | — |
pls4all.R.mdatools | ✗ +2e+02 | 19.7 ms | — | — | — | 6.38 ms | 8.96 ms | — | — | — | — | — | — | — | — |
pls4all.R.pls | ✗ +2e+02 | 21.1 ms | — | — | — | 5.57 ms | 9.96 ms | — | — | — | — | — | — | — | — |
| MATLAB · pls4all |
pls4all.matlab | ✗ +5e+01 | 21.6 ms | — | — | — | 31.7 ms | 72.4 ms | — | — | — | — | — | — | — | — |
pls4all.matlab.classdef | ✗ +5e+01 | 22.0 ms | — | — | — | 29.8 ms | 70.5 ms | — | — | — | — | — | — | — | — |
| R · external |
📐ref.r_pls | source | 42.6 ms | — | — | — | 85.7 ms | 124.9 ms | — | — | — | — | — | — | — | — |
:::
:::{tab-item} 3 threads
:sync: threads-3
| Backend | Parity | 50×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-15 | — | — | — | — | 25.9 ms | — | — | — | — | — | — | — | — | — |
pls4all.cpp.blas+omp | ✓ ref 2e-15 | — | — | — | — | 25.9 ms | — | — | — | — | — | — | — | — | — |
pls4all.cpp.omp | ✓ ref 2e-15 | — | — | — | — | 28.5 ms | — | — | — | — | — | — | — | — | — |
pls4all.cpp.ref | ✓ ref 2e-15 | — | — | — | — | 26.3 ms | — | — | — | — | — | — | — | — | — |
| Python · pls4all |
pls4all.python | ✓ bind | — | — | — | — | 25.9 ms | — | — | — | — | — | — | — | — | — |
pls4all.sklearn | ✓ bind | — | — | — | — | 25.8 ms🏆 | — | — | — | — | — | — | — | — | — |
| R · pls4all |
pls4all.R | ✗ +4e+01 | — | — | — | — | 3.50 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.formula | ✗ +4e+01 | — | — | — | — | 5.59 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.mdatools | ✗ +4e+01 | — | — | — | — | 5.62 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.pls | ✗ +4e+01 | — | — | — | — | 4.87 ms | — | — | — | — | — | — | — | — | — |
| MATLAB · pls4all |
pls4all.matlab | ✗ +5e+01 | — | — | — | — | 26.1 ms | — | — | — | — | — | — | — | — | — |
pls4all.matlab.classdef | ✗ +5e+01 | — | — | — | — | 26.7 ms | — | — | — | — | — | — | — | — | — |
| R · external |
📐ref.r_pls | source | — | — | — | — | 87.8 ms | — | — | — | — | — | — | — | — | — |
:::
:::{tab-item} 10 threads
:sync: threads-10
| Backend | Parity | 50×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-15 | — | — | — | — | 24.6 ms | — | — | — | — | — | — | — | — | — |
pls4all.cpp.blas+omp | ✓ ref 2e-15 | — | — | — | — | 24.7 ms | — | — | — | — | — | — | — | — | — |
pls4all.cpp.omp | ✓ ref 2e-15 | — | — | — | — | 26.7 ms | — | — | — | — | — | — | — | — | — |
pls4all.cpp.ref | ✓ ref 2e-15 | — | — | — | — | 25.0 ms | — | — | — | — | — | — | — | — | — |
| Python · pls4all |
pls4all.python | ✓ bind | — | — | — | — | 24.6 ms🏆 | — | — | — | — | — | — | — | — | — |
pls4all.sklearn | ✓ bind | — | — | — | — | 25.5 ms | — | — | — | — | — | — | — | — | — |
| R · pls4all |
pls4all.R | ✗ +4e+01 | — | — | — | — | 3.10 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.formula | ✗ +4e+01 | — | — | — | — | 3.71 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.mdatools | ✗ +4e+01 | — | — | — | — | 3.82 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.pls | ✗ +4e+01 | — | — | — | — | 4.03 ms | — | — | — | — | — | — | — | — | — |
| MATLAB · pls4all |
pls4all.matlab | ✗ +5e+01 | — | — | — | — | 25.1 ms | — | — | — | — | — | — | — | — | — |
pls4all.matlab.classdef | ✗ +5e+01 | — | — | — | — | 25.6 ms | — | — | — | — | — | — | — | — | — |
| R · external |
📐ref.r_pls | source | — | — | — | — | 71.3 ms | — | — | — | — | — | — | — | — | — |
:::
::::
---
_See also_: [benchmark overview](../benchmarks/overview.md) · [methods index](index.md) · [interactive dashboard](../landing/dashboard.md)