term_indices: Get term indices from a model or term

View source: R/all_generic.R

term_indicesR Documentation

Get term indices from a model or term

Description

Get the indices that map between model terms and their corresponding columns in the design matrix. These indices are essential for:

  • Extracting coefficients for specific terms

  • Computing contrasts for specific model components

  • Mapping between event terms and baseline terms

  • Identifying which design matrix columns belong to which terms

Usage

term_indices(x, ...)

Arguments

x

The model or term object (typically an fmri_model, event_model, or convolved_term)

...

Additional arguments passed to methods

Value

A named list where each element contains the column indices in the design matrix corresponding to that term. For example:

  • For event terms: Indices for each experimental condition

  • For baseline terms: Indices for drift and block terms

  • For convolved terms: Indices for each basis function

See Also

event_terms(), baseline_terms(), design_matrix()

Other model_components: baseline_terms(), event_terms()

Examples

# Create a model with multiple terms
event_data <- data.frame(
  stimulus = factor(c("face", "house", "face", "house")),
  rt = c(0.8, 1.2, 0.9, 1.1),
  onsets = c(1, 10, 20, 30),
  run = c(1, 1, 1, 1)
)

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

# Create event model with multiple terms
evmodel <- event_model(
  onsets ~ hrf(stimulus) + hrf(rt, basis = "fourier", nbasis = 2),
  data = event_data,
  block = ~run,
  sampling_frame = sframe
)

# Get indices for each term
indices <- term_indices(evmodel)
# Returns list with:
#  - Indices for stimulus conditions
#  - Indices for rt basis functions

# Create full model with baseline
bmodel <- baseline_model(basis = "bs", degree = 3, sframe = sframe)
fmodel <- fmri_model(evmodel, bmodel)

# Get indices for full model
full_indices <- term_indices(fmodel)
# Returns indices for both event and baseline terms

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