Skip to contents

Compute and return the fitted hemodynamic response function (HRF) for a model object. The HRF represents the expected BOLD response to neural activity. For models with multiple basis functions, this returns the combined HRF shape.

Usage

fitted_hrf(x, sample_at, ...)

Arguments

x

An object for which the fitted HRF should be computed

sample_at

A vector of time points at which the HRF should be sampled

...

Additional arguments passed to methods

Value

A numeric vector containing the fitted HRF values at the requested time points

Details

This generic function computes the fitted hemodynamic response function (HRF) for an object. The method needs to be implemented for specific object types.

Examples

# Create a simple dataset with two conditions
X <- matrix(rnorm(100 * 100), 100, 100)  # 100 timepoints, 100 voxels
event_data <- data.frame(
  condition = factor(c("A", "B", "A", "B")),
  onsets = c(1, 25, 50, 75),
  run = c(1, 1, 1, 1)
)

# Create dataset and sampling frame
dset <- fmridataset::matrix_dataset(X, TR = 2, run_length = 100, event_table = event_data)
sframe <- sampling_frame(blocklens = 100, TR = 2)

# Create event model with canonical HRF
evmodel <- event_model(
  onsets ~ hrf(condition),
  data = event_data,
  block = ~run,
  sampling_frame = sframe
)

# Fit model
fit <- fmri_lm(
  onsets ~ hrf(condition),
  block = ~run,
  dataset = dset
)

# Get fitted HRF at specific timepoints
times <- seq(0, 20, by = 0.5)  # Sample from 0-20s every 0.5s
hrf_values <- fitted_hrf(fit, sample_at = times)