samples: Extract sampling times

View source: R/all_generic.R

samplesR Documentation

Extract sampling times

Description

Get the sampling times for a regressor or sampling frame. These times represent when fMRI data was acquired and can be either relative (within each run) or global (cumulative across runs). Sampling times are used to:

  • Evaluate regressors at scan acquisition times

  • Align model predictions with data collection

  • Convert between TR-based and time-based representations

Usage

samples(x, ...)

Arguments

x

The object containing timing information (typically a sampling_frame or regressor)

...

Additional arguments passed to methods. Common arguments include:

blockids

Numeric vector specifying which blocks/runs to include

global

Logical; if TRUE, return cumulative times across runs

Value

A numeric vector of sampling times in seconds, where:

  • Each value represents a scan acquisition time

  • Times account for TR (repetition time) spacing

  • If global=FALSE, times reset at the start of each run

  • If global=TRUE, times accumulate across runs

See Also

sampling_frame(), regressor(), global_onsets()

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

Examples

# Create a sampling frame with multiple runs
sframe <- sampling_frame(
  blocklens = c(100, 100, 100),  # 100 scans per run
  TR = 2,                        # 2 seconds per scan
  start_time = 0                 # Start at time 0
)

# Get relative sampling times (reset each run)
rel_times <- samples(sframe)
# First few times: 0, 2, 4, 6, ... (resets each run)

# Get global sampling times (cumulative)
glob_times <- samples(sframe, global = TRUE)
# Shows: 0, 2, 4, ..., 198, 200, 202, ..., 598

# Get times for specific runs
run2_times <- samples(sframe, blockids = 2)
# Times for second run only

# Create regressor and get its sampling times
event_data <- data.frame(
  onsets = c(1, 10, 20),
  run = c(1, 1, 1)
)
reg <- regressor(
  onsets = event_data$onsets,
  sampling_frame = sframe
)
reg_times <- samples(reg)

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