Skip to contents

Fits OLS of Y on X, estimates a noise model from the residuals with fit_noise(), and whitens X and Y with it. Because the residuals are OLS residuals from X by construction, X is passed to fit_noise() as design, correcting the bias that fitting puts into their autocorrelation; pass design = FALSE to turn the correction off.

Usage

whiten(X, Y, runs = NULL, censor = NULL, ...)

Arguments

X

Design matrix (time x regressors).

Y

Data matrix (time x voxels).

runs

Optional run labels.

censor

Optional censor indices.

...

Additional parameters passed to fit_noise().

Value

List with whitened X and Y matrices.

Examples

# Create example data
n_time <- 200
n_pred <- 3
n_voxels <- 50
X <- matrix(rnorm(n_time * n_pred), n_time, n_pred)
Y <- X %*% matrix(rnorm(n_pred * n_voxels), n_pred, n_voxels) +
     matrix(rnorm(n_time * n_voxels, sd = 2), n_time, n_voxels)

# One-step whitening
whitened <- whiten(X, Y, method = "ar", p = 2)