nirspipe.pipeline.glm_worsley#

Worsley’s bias-corrected AR noise model for the GLM (--noise-model worsley).

The AR coefficients come from the OLS residual’s autocovariances after removing the bias the fit puts into them, as fmristat’s fmrilm.m does (Worsley et al., 2002): the residual is the data with the design projected out, which leaves its autocovariances short of the noise’s, most of all at the low frequencies the drift terms absorb. Each lag’s sum of products has expectation \(\sum_k M_{jk} a_k\) in the noise autocovariances \(a_k\), with

\[M_{jk} = \frac{\operatorname{tr}(R D_j R D_k)}{1 + [j > 0]}\]

where \(R\) forms the residual from the design and \(D_j\) is the symmetric lag-j shift (\(D_0\) the identity), so \(a = M^{-1} c\) is solved for and its AR coefficients found by Levinson-Durbin. A channel whose corrected autocovariances are not positive definite at the order asked for is fitted as auto would fit it.

On a run with BAD_ spans the residual and the lag products cover kept frames only, and \(R\) is the kept rows’ residual-forming matrix, zero on the censored ones, so the same expectation holds.

Module Contents#

Functions#

worsley_order

worsley -> 4x the sampling rate, as auto; worsley5 -> 5.

bias_matrix

fmristat’s M for lags 0..order, from an orthonormal basis rather than the n x n matrices.

lag_products

sum_t r[t] r[t + j] for j = 0..order, over pairs of kept frames only.

levinson

Yule-Walker coefficients from autocovariances by Levinson-Durbin, None when not positive definite.

worsley_rho

One channel’s bias-corrected AR coefficients, None when they cannot be had at this order.

fit_worsley

Every channel fitted under the bias-corrected AR model, in mne-nirs’ results container.

Data#

API#

nirspipe.pipeline.glm_worsley.logger = 'get_logger(...)'#
nirspipe.pipeline.glm_worsley.NOISE_PREFIX = 'worsley'#
nirspipe.pipeline.glm_worsley.worsley_order(noise_model: str, sfreq: float) → int#

worsley -> 4x the sampling rate, as auto; worsley5 -> 5.

nirspipe.pipeline.glm_worsley.bias_matrix(design: numpy.ndarray, keep: numpy.ndarray, order: int) → numpy.ndarray#

fmristat’s M for lags 0..order, from an orthonormal basis rather than the n x n matrices.

tr(R D_j R D_k) with R = W - Q Q' (W the kept-frame mask, Q the basis) expands to tr(W D_j W D_k) - 2 tr(Q' D_j W D_k Q) + tr(A_j A_k), A_j = Q' D_j Q; the first term is nonzero only for j = k, where it counts the kept frames (lag 0) or twice the pairs of kept frames j apart.

nirspipe.pipeline.glm_worsley.lag_products(resid: numpy.ndarray, keep: numpy.ndarray, order: int) → numpy.ndarray#

sum_t r[t] r[t + j] for j = 0..order, over pairs of kept frames only.

nirspipe.pipeline.glm_worsley.levinson(acov: numpy.ndarray, order: int) → numpy.ndarray | None#

Yule-Walker coefficients from autocovariances by Levinson-Durbin, None when not positive definite.

rho is in nilearn’s sign convention, y[t] - sum(rho[k] * y[t-k-1]) white:

acov [1, 0.5, 0.25], order 2  ->  [0.5, 0.0]
nirspipe.pipeline.glm_worsley.worsley_rho(resid: numpy.ndarray, keep: numpy.ndarray, m: numpy.ndarray) → numpy.ndarray | None#

One channel’s bias-corrected AR coefficients, None when they cannot be had at this order.

nirspipe.pipeline.glm_worsley.fit_worsley(haemo: mne.io.BaseRaw, design_matrix: pandas.DataFrame, noise_model: str, keep: numpy.ndarray | None = None) → tuple[Any, list[str]]#

Every channel fitted under the bias-corrected AR model, in mne-nirs’ results container.

Returns the results and the channels fitted as auto instead. Without keep the fit is nilearn’s AR model, as auto’s; with it, the censored fit of nirspipe.pipeline.glm_censored.fit_channel(), whitened on the full axis and refitted on the kept rows.