fitted_hrf: Evaluate a regressor object over a time grid

View source: R/all_generic.R

fitted_hrfR Documentation

Evaluate a regressor object over a time grid

Description

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

grid

A numeric vector specifying the time points at which to evaluate the regressor

Details

Generic function to evaluate a regressor object over a specified time grid. Different types of regressors may have different evaluation methods.

Value

A numeric vector or matrix containing the evaluated regressor values

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

See Also

fmrihrf::single_trial_regressor(), regressor()

fmrihrf::HRF_SPMG1(), fmri_lm()

Other hrf: nbasis(), penalty_matrix()

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)

bbuchsbaum/fmrireg documentation built on June 10, 2025, 8:18 p.m.