convolve: Convolve a term with a hemodynamic response function

View source: R/all_generic.R

convolveR Documentation

Convolve a term with a hemodynamic response function

Description

This function convolves an event sequence with a hemodynamic response function (HRF) over a specified time series grid. The convolution models the expected BOLD response to the events. For event-related designs, each event is convolved with the HRF and the results are summed. For block designs, the duration of each event is taken into account during convolution.

Usage

convolve(x, hrf, sampling_frame, ...)

Arguments

x

The event sequence (typically an event_term or event_model)

hrf

The hemodynamic response function to use for convolution

sampling_frame

The time series grid over which to sample the convolved function

...

Additional arguments passed to methods. Common arguments include:

  • drop.emptyLogical; if TRUE, empty events are dropped

  • summateLogical; if TRUE, sum the convolved HRF over event durations

  • precisionNumeric; precision of HRF sampling (default: 0.3)

Value

A tibble containing the convolved design matrix, with columns for each condition

See Also

HRF_SPMG1(), event_term(), sampling_frame()

Examples

# Create a simple event-related design
event_data <- data.frame(
  condition = factor(c("A", "B", "A", "B")),
  onsets = c(1, 10, 20, 30),
  run = c(1, 1, 1, 1)
)

# Create a sampling frame
sframe <- sampling_frame(blocklens = 50, TR = 2)

# Create an event term
eterm <- event_term(
  list(condition = event_data$condition),
  onsets = event_data$onsets,
  blockids = event_data$run
)

# Convolve with canonical HRF
convolved <- convolve(eterm, HRF_SPMG1, sframe)

# Convolve with multiple basis functions
convolved_fourier <- convolve(
  eterm, 
  getHRF("fourier", nbasis = 2),
  sframe
)

bbuchsbaum/fmrireg documentation built on March 1, 2025, 11:20 a.m.