OASIS Theory: What Is Reused, Solved, and Returned
Source:vignettes/oasis_theory.Rmd
oasis_theory.RmdOASIS computes least squares separate (LSS) estimates by reusing the calculations shared across trial models, then solving the small trial-specific systems in batches. With zero ridge penalties, it gives the ordinary LSS estimator. Nonzero penalties give a regularized LSS estimator.
This article defines what OASIS estimates, derives the linear systems
it solves for one and for several HRF basis functions per trial, and
maps each mathematical object to the current implementation. Read it
after vignette("fmrilss") and
vignette("oasis_method"); those articles introduce the
practical meaning of LSS and the user-facing OASIS API.
Scope and notation
The dimensions below are used throughout.
| Symbol | Meaning |
|---|---|
| T | time points |
| V | response columns or voxels |
| N | trials in the condition being estimated |
| K | HRF basis columns per trial |
| K_z | columns supplied in the common nuisance design |
| p | rank of the common nuisance design; p <= K_z |
| B | voxel block size used for data products |
Let be the data and the common design: intercepts, drifts, nuisance variables, and aggregates for conditions not being estimated. Only the column space of matters. If is an orthonormal basis for that space, then the residualizing projection
removes from any vector its component in that space. The implementation rank-reduces before passing it to the compiled kernels, so redundant nuisance columns do not add arbitrary projection directions.
For trial , let contain its HRF basis columns and define
so is the sum of the basis columns of all other trials. The Frisch–Waugh–Lovell theorem says that the coefficients on and are unchanged if is dropped from the model and , , and are residualized by instead. After this reduction, the trial-wise model is
where . OASIS returns . For , each trial contributes one scalar coefficient per voxel. For , each trial contributes rows of basis coefficients. Converting those coefficients to a single response amplitude requires a separate definition and normalization.
One-basis system
For , is a single column . Write , , and . The design scalars, which depend on the design but not on and are therefore computed once for all voxels, are
The C++ source, and the diagnostics returned with
return_diag = TRUE, name these quantities d,
alpha, and s, respectively; note that the
code’s s is
,
not the summed column
.
For all voxels at once, define
and
.
With ridge penalties
on the trial coefficient and
on the other-trials coefficient (both zero for ordinary LSS; see Ridge changes the estimator),
the penalized normal equations are
Here each right-hand-side row has length . Inverting the matrix gives
When both penalties are zero and the two-column trial model has full
rank, this is exactly the ordinary LSS coefficient. A rank-deficient
unpenalized model is not identifiable, and the public OASIS path,
lss(..., method = "oasis"), stops with an error rather than
silently adding a small diagonal jitter. This
form assumes
;
with one trial there is no “other trials” column, and OASIS solves the
one-column target model instead.
Multi-basis system
For , define the residualized blocks , , and . The cached blocks are
With and , OASIS solves
The implementation factorizes one Gram matrix per trial and uses all voxel columns as right-hand sides. The unpenalized public path requires every such Gram matrix to have rank . For , the corresponding target-only system is .
An executable equality check
We check the implementation against independently assembled trial-wise GLMs. The fixed example below compares every trial, basis coefficient, and voxel for both and .
Set both penalties to zero for ordinary LSS; OASIS uses fractional ridge by default.
unpenalized <- oasis_options(
ridge_mode = "absolute",
ridge_x = 0,
ridge_b = 0,
return_se = TRUE
)
fit1 <- lss(Y1, X1, Z = Z, method = "oasis", oasis = unpenalized)
dim(fit1$beta)
#> [1] 6 5| Basis_dimension | Maximum_beta_error | Maximum_SE_error |
|---|---|---|
| 1 | 0 | 0 |
| 3 | 0 | 0 |
The vignette build stops if either maximum discrepancy reaches . These checks use a correctly specified fixed design with common coefficients for the summed trial signal and independent Gaussian errors. They verify numerical agreement with the corresponding GLMs in these examples. Uncertainty for ridge, estimated whitening, and data-adaptive HRF selection requires additional methods.
Ridge changes the estimator
For each trial and voxel, the ridge estimate minimizes
With ridge_mode = "absolute", ridge_x and
ridge_b are the penalties in that expression. With
ridge_mode = "fractional", the implementation multiplies
them by mean residualized design energies, where a column’s energy is
its squared norm after residualization:
- for , the means of and ;
- for , the mean diagonal entries of and , averaged over trials.
Because of this scaling, multiplying the whole trial design by a common constant leaves the intended relative penalty unchanged. Fractional scaling does not make arbitrary, separate rescalings of individual multi-basis columns equivalent. Ridge can stabilize a poorly conditioned system, but its coefficients are penalized estimates rather than ordinary LSS coefficients.
The package default is fractional ridge with
ridge_x = ridge_b = 0.05. Request zero penalties explicitly
when exact unpenalized LSS is the target. The public path checks that
each penalized multi-trial Gram matrix is positive definite before
solving it. When
,
there is no identifiable “other trials” coefficient, so OASIS solves
only the target block; ridge_b is then irrelevant.
What the standard errors mean
The model-based standard errors below apply under the following conditions:
-
ridge_x = ridge_b = 0; - for , the trial-specific -column model is full rank; for , the target -column model is full rank;
- prewhitening is not estimated in the same call;
- the chosen HRF design is treated as fixed;
- residual degrees of freedom are positive;
- conditional errors have spherical covariance, for each voxel .
The API checks the rank, penalty, and fitting-mode restrictions. The error covariance assumption must be assessed for the data; the function cannot verify it from the design alone.
For trial , let be its identifiable unpenalized model Gram matrix: when and when . The implementation computes
and takes the square roots of the relevant diagonal entries of
.
Thus the reported values are the same conditional, homoskedastic-model
standard errors as in the corresponding full GLM under uncorrelated,
constant-variance temporal errors. Gaussianity is an additional
requirement for exact finite-sample t inference. The values are not
ridge standard errors, not heteroskedasticity- or autocorrelation-robust
errors, and not calibrated for uncertainty introduced by estimating a
whitening model or selecting an HRF from the same data.
oasis_options() rejects ridge together with
return_se = TRUE; the backend also rejects estimated
prewhitening and voxel-adaptive HRF modes for this request.
Prewhitening is set by prewhiten, not
oasis
Temporal whitening is handled by the top-level prewhiten
argument and the shared fmriAR integration. The same
estimated linear transformation is applied to
,
the trial design, and the common design before the OASIS algebra
runs.
fit_ar1 <- lss(
Y,
X,
Z = Z,
method = "oasis",
oasis = oasis_options(),
prewhiten = prewhiten_options(method = "ar", p = 1)
)For multiple runs, supply pooling = "run" and the run
labels. The legacy oasis$whiten field is deprecated and
ignored with a warning; use prewhiten instead. Coefficients
remain available after estimated whitening, but
return_se = TRUE fails closed: the call stops with an error
instead of returning standard errors, because uncertainty for feasible
GLS (GLS with an estimated noise covariance) is not calibrated here.
Design construction and trial/basis identity
There are two supported routes into the same solver:
-
Xsupplies an already convolved trial design. -
oasis$design_specasks the backend to construct one from event onsets withfmrihrf.
The event route (2) preserves event duration and amplitude and adds
aggregate regressors for other conditions to the common nuisance span.
In multi-run low-level design specifications, onsets are global seconds
rather than within-run times; lss_design() with a
fmridesign::event_model() is the safer run-aware
interface.
A raw multi-basis X cannot reveal trial identity from
dimensions alone. It therefore requires explicit K,
ntrials, and a trial_basis_map identifying
every uniquely named column. The output contains
rows in canonical trial-by-basis order. Supplying an incorrect grouping
would change the model being fitted, so ambiguous trial/basis mappings
are rejected.
If design_spec$hrf_grid is supplied, the implementation
uses the observed data to choose a candidate HRF from the grid before
fitting. That is a model-selection step. Treat the resulting
coefficients as conditional on the selected design. Because ordinary
post-selection standard errors are not established by the fixed-design
formula above, this route rejects return_se = TRUE.
The vignette also checks output and diagnostic dimensions, preservation of trial/basis identity after column permutations, and the expected response to rescaling. It checks that unsupported standard-error requests produce errors.
Computational cost and memory
For multiple trials, each full LSS design has effective columns: common columns, target columns, and aggregate-other columns. The table below lists the leading costs for a dense design with and nuisance rank .
| Stage | K = 1 | general K |
|---|---|---|
| Rank-reveal common design | O(T K_z^2) | O(T K_z^2) |
| Residualize all trial columns | O(T p N) | O(T p N K) |
| Build trial Gram terms | O(T N) | O(T N K^2) |
| Residualize all voxel data | O(T p V) | O(T p V) |
| Trial-data cross-products | O(T N V) | O(T N K V) |
| Solve all trial systems | O(N V) | O(N K^3 + N K^2 V) |
The
cross-product is usually the largest OASIS term when both the trial and
voxel counts are large. block_cols = B limits the temporary
voxel block to
,
but it does not remove the
products or the
output. Other persistent storage includes
for the nuisance basis,
for the residualized trial design, and
for multi-basis Gram blocks.
A direct implementation that refits each trial model separately performs factorizations of designs and repeatedly forms trial-specific products with . OASIS reuses the nuisance projection, aggregate design, Gram terms, and batched products. The time saved depends on , BLAS, memory bandwidth, block size, and the implementation used for comparison; the operation counts do not imply a fixed speedup.
Implementation map and return values
These names are internal implementation landmarks, not additional public APIs.
| Responsibility | Location |
|---|---|
| Validate options, assemble common span, dispatch | R/oasis_backend.R: .lss_oasis |
| Build event-based trial and other-condition designs | R/oasis_design.R: .oasis_build_X_from_events |
| Resolve absolute or fractional ridge | R/oasis_ridge_se.R: .oasis_resolve_ridge |
| One-basis design cache and blocked products | src/oasis_core.cpp: oasis_precompute_design, oasis_AtY_SY_blocked |
| One-basis coefficient solve | src/oasis_core.cpp: oasis_betas_closed_form |
| Multi-basis design cache and blocked products | src/oasis_core.cpp: oasisk_precompute_design, oasisk_products |
| Multi-basis coefficient and SE solves | src/oasis_core.cpp: oasisk_betas, oasisk_betas_se |
By default, the public result is an
coefficient matrix (an
matrix when
).
Setting return_se = TRUE or return_diag = TRUE
changes the result to list(beta, diag?, se?);
beta and se have the same
shape. For
,
d, alpha, and s are
length-
diagnostic vectors. For
,
D, C, and E are
arrays. These are unpenalized cross-products on the residualized design
scale, after any requested whitening. They can expose low energy or
collinearity, but they are not a condition-number report and do not by
themselves validate a chosen ridge.
Boundaries of the result
- Exact equality with classical LSS requires zero ridge, a fixed design, and full-rank trial models.
- Multi-basis output is a vector of basis coefficients per trial and voxel; any scalar amplitude needs an explicit, identified normalization rule.
- Estimated whitening changes the fitted space and adds uncertainty not covered by the conditional standard-error formula.
- HRF grid selection and voxel-adaptive HRFs are data-adaptive procedures; fixed-design uncertainty does not automatically survive selection.
- Blocking controls temporary memory. It cannot make storage smaller than the requested result.
Next steps
- Continue to
vignette("lss_with_fmridesign")for run-aware event-table construction and trial/basis identity. - Return to
vignette("oasis_method")for fitting and diagnostics, orvignette("fmrilss")for the basic LSS workflow. - Later articles cover explicitly normalized voxel-specific HRF shapes
in
vignette("voxel-wise-hrf")and library-constrained shapes and trial coefficients invignette("sbhm").
Reference
Mumford, J. A., Turner, B. O., Ashby, F. G., & Poldrack, R. A. (2012). Deconvolving BOLD activation in event-related designs for multivoxel pattern classification analyses. NeuroImage, 59(3), 2636–2643. https://doi.org/10.1016/j.neuroimage.2011.08.076