global_onsets: Return the global onsets of an object

View source: R/all_generic.R

global_onsetsR Documentation

Return the global onsets of an object

Description

Convert relative onset times to global (cumulative) onset times across runs. Global onsets are defined as cumulative time over runs, meaning they do not reset to zero for each run. This is useful for:

  • Converting run-specific onsets to experiment-wide timings

  • Aligning events across multiple runs

  • Computing temporal distances between events in different runs

Usage

global_onsets(x, onsets, ...)

Arguments

x

The object containing timing information (typically a sampling_frame)

onsets

A numeric vector of relative onset times within each run/block

...

Additional arguments passed to methods. Common arguments include:

blockids

Numeric vector specifying which block/run each onset belongs to

TR

Numeric; repetition time in seconds

Value

A numeric vector of global onset times where:

  • Each onset is adjusted by the cumulative duration of previous runs

  • Times are in the same units as the input onsets (typically seconds)

  • NA is returned for onsets that exceed their block duration

See Also

sampling_frame(), event_model()

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

Examples

# Create a sampling frame with three runs
sframe <- sampling_frame(
  blocklens = c(100, 100, 100),  # 100 scans per run
  TR = 2                         # 2 seconds per scan
)

# Define events in each run
run_onsets <- c(10, 20, 30)     # Events at 10s, 20s, 30s
run_ids <- c(1, 2, 3)           # One event per run

# Convert to global onsets
global_times <- global_onsets(
  sframe,
  onsets = run_onsets,
  blockids = run_ids
)
# Returns: c(10, 220, 430)
# Because:
#  - Run 1: 10s
#  - Run 2: 20s + (100 scans * 2s) = 220s
#  - Run 3: 30s + (200 scans * 2s) = 430s

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