Skip to contents

`regressor_design` extends [regressor_set()] by allowing onsets to be specified relative to individual blocks and by directly returning the evaluated design matrix.

Usage

regressor_design(
  onsets,
  fac,
  block,
  sframe,
  hrf = HRF_SPMG1,
  duration = 0,
  amplitude = 1,
  span = 40,
  precision = 0.33,
  method = c("conv", "loop", "fft", "Rconv"),
  sparse = FALSE,
  summate = TRUE
)

Arguments

onsets

Numeric vector of event onset times, expressed relative to the start of their corresponding block.

fac

A factor (or object coercible to a factor) indicating the condition for each onset.

block

Integer vector identifying the block for each onset. Values must be valid block indices for `sframe`.

sframe

A [sampling_frame] describing the temporal structure of the experiment.

hrf

Hemodynamic response function shared by all conditions.

duration

Numeric scalar or vector of event durations.

amplitude

Numeric scalar or vector of event amplitudes.

span

Numeric scalar giving the HRF span in seconds.

precision

Numeric precision used during convolution.

method

Evaluation method passed to [evaluate()].

sparse

Logical; if `TRUE` a sparse design matrix is returned.

summate

Logical; passed to [regressor()].

Each block (run) is convolved separately: the rows of a block depend only on the events of that block, so a response that starts near the end of one run is truncated at the run boundary rather than carried into the next run.

Value

A numeric matrix (or sparse matrix) with one row per sample defined by `sframe` (blocks stacked in order) and `nbasis(hrf)` columns per factor level, in the order of `levels(fac)`. Columns are named after the levels; when `nbasis(hrf) > 1` they are named `<level>_basis<k>`.

Examples

# Create a sampling frame for 2 blocks, 100 scans each, TR=2
sframe <- sampling_frame(blocklens = c(100, 100), TR = 2)

# Events in block-relative time
onsets <- c(10, 30, 50, 20, 40, 60)
conditions <- factor(c("A", "B", "A", "B", "A", "B"))
blocks <- c(1, 1, 1, 2, 2, 2)

# Build design matrix
design <- regressor_design(
  onsets = onsets,
  fac = conditions,
  block = blocks,
  sframe = sframe,
  hrf = HRF_SPMG1
)

# Design matrix has 200 rows (total scans) and 2 columns (conditions)
dim(design)
#> [1] 200   2