onsets: Get event onsets from an object

View source: R/all_generic.R

onsetsR Documentation

Get event onsets from an object

Description

Extract the onset times of events from a model object. Onsets represent the timing of experimental events in an fMRI design, typically in seconds from the start of each run. These times are used to:

  • Create regressors by convolving with HRF

  • Verify event timing in the design

  • Analyze temporal patterns of events

Usage

onsets(x)

## S3 method for class 'regressor'
onsets(x)

Arguments

x

The object containing event information (typically an event_term or event_model)

Value

A numeric vector of onset times in seconds, where:

  • Each value represents the start time of an event

  • Times are relative to the start of each run

  • Order matches the original event sequence

See Also

event_term(), event_model(), global_onsets()

Other timing: durations(), global_onsets(), samples()

Examples

# Create event data with multiple conditions
event_data <- data.frame(
  condition = factor(c("face", "house", "face", "house")),
  onsets = c(1, 10, 20, 30),
  run = c(1, 1, 1, 1)
)

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

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

# Get onsets from term
onset_times <- onsets(eterm)  # Returns: c(1, 10, 20, 30)

# Create and get onsets from event model
evmodel <- event_model(
  onsets ~ hrf(condition),
  data = event_data,
  block = ~run,
  sampling_frame = sframe
)

model_onsets <- onsets(evmodel)

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