Skip to contents

Compute LSS trial-wise betas when each voxel has its own HRF formed as a linear combination of K basis kernels sampled on the TR grid.

Usage

lss_with_hrf_pure_r(
  Y,
  onset_idx,
  durations = NULL,
  hrf_basis_kernels,
  coefficients,
  Z = NULL,
  Nuisance = NULL,
  verbose = FALSE,
  method = c("r", "cpp", "cpp_arma", "cpp_omp"),
  basis_convolved = NULL
)

Arguments

Y

numeric matrix (n_time x n_vox)

onset_idx

integer vector (length n_trials), 1-based TR indices

durations

numeric vector (length n_trials), in TRs; 0 means an impulse. Uses inclusive indexing: if duration = d, samples o:(o+d) are 1.

hrf_basis_kernels

numeric matrix (L x K), K basis kernels on TR grid

coefficients

numeric matrix (K x n_vox), voxel-wise HRF weights

Z

optional numeric matrix (n_time x F) of experimental regressors; if NULL, an intercept (column of 1s) is used.

Nuisance

optional numeric matrix (n_time x q) of confounds to project out

verbose

logical; print progress every 1000 voxels

method

character: "r" (default, pure R), "cpp" (C++ backend), "cpp_arma" (Armadillo backend), or "cpp_omp" (OpenMP parallel backend). Falls back automatically: cpp_omp -> cpp_arma -> cpp -> r.

basis_convolved

Optional precomputed list of K matrices, each n_time x n_trials. When supplied, the onset-index construction is bypassed.

Value

numeric matrix (n_trials x n_vox) of trial-wise beta estimates

Details

Design & nuisance handling match lss():

  • The trial-of-interest (Xi) and the sum of all other trials (Xother) are included in each per-trial GLM.

  • Y and the trial regressors are residualized against the complete cbind(Z, Nuisance) span, matching the full-model/FWL contract in lss().

  • If Z is NULL, an intercept-only design is used.

Examples

# \donttest{
set.seed(1)
Y <- matrix(rnorm(40 * 2), 40, 2)
onset_idx <- c(5L, 20L, 32L)
durations <- rep(0L, length(onset_idx))
time <- 0:12
basis <- cbind(exp(-time / 3), time * exp(-time / 3))
coeffs <- matrix(c(1, 0.2, 0.8, -0.1), 2, 2)
betas <- fmrilss:::lss_with_hrf_pure_r(
  Y, onset_idx, durations, basis, coeffs, Z = NULL, Nuisance = NULL
)
betas_cpp <- fmrilss:::lss_with_hrf_pure_r(
  Y, onset_idx, durations, basis, coeffs, method = "cpp"
)
# }