Skip to contents

Creates a simple boxcar (step function) HRF that is constant within a time window starting at t=0 and zero outside. Unlike traditional HRFs, this has no hemodynamic delay - it represents an instantaneous response.

Usage

hrf_boxcar(width, amplitude = 1, normalize = FALSE)

Arguments

width

Duration of the boxcar window in seconds.

amplitude

Height of the boxcar (default: 1).

normalize

Logical; if TRUE, the boxcar is scaled so that its integral equals 1 (i.e., amplitude = 1/width), so the regression coefficient estimates the integrated signal in the window rather than its mean. Default is FALSE.

Value

An HRF object that can be used with regressor() and other fmrihrf functions.

Details

In a least-squares GLM, an isolated event's coefficient for a boxcar of amplitude 1 estimates the mean signal in the window. With normalize = TRUE the boxcar has unit area (amplitude 1/width), so the coefficient estimates the integrated signal over the window (the mean multiplied by width).

For delayed windows (not starting at t=0), use lag_hrf to shift the boxcar in time.

Note on durations

The width is fixed when the HRF is created. The duration parameter in regressor() does not modify the boxcar width—it controls how long the neural input is sustained (which then gets convolved with this HRF). For trial-varying boxcar widths, use a list of HRFs:


widths <- c(4, 6, 8)
hrfs <- lapply(widths, function(w) hrf_boxcar(width = w, normalize = TRUE))
reg <- regressor(onsets = c(0, 20, 40), hrf = hrfs)

See also

Examples

# Simple boxcar of 5 seconds width
hrf1 <- hrf_boxcar(width = 5)
t <- seq(-1, 10, by = 0.1)
plot(t, evaluate(hrf1, t), type = "s", main = "Simple Boxcar HRF")


# Unit-area boxcar: beta estimates the integrated signal over 0-5 s
# (5 x the mean); with amplitude 1, beta estimates the mean itself
hrf2 <- hrf_boxcar(width = 5, normalize = TRUE)

# Use in a regressor with trial-varying widths
hrf_short <- hrf_boxcar(width = 4, normalize = TRUE)
hrf_long <- hrf_boxcar(width = 8, normalize = TRUE)
reg <- regressor(onsets = c(0, 20), hrf = list(hrf_short, hrf_long))

# For delayed windows, use lag_hrf decorator
hrf_delayed <- lag_hrf(hrf_boxcar(width = 5), lag = 10)  # Window from 10-15s