design_matrix: design_matrix

View source: R/all_generic.R

design_matrixR Documentation

design_matrix

Description

Extract or construct the design matrix from a model term or object. The design matrix contains the predictor variables used in the model, with one row per time point and one column per predictor. For event-related designs, the design matrix typically contains the convolved HRF responses. For baseline terms, it contains drift and nuisance regressors.

Usage

design_matrix(x, ...)

## S3 method for class 'convolved_term'
design_matrix(x, blockid = NULL, ...)

## S3 method for class 'afni_hrf_convolved_term'
design_matrix(x, blockid = NULL, ...)

## S3 method for class 'baseline_model'
design_matrix(x, blockid = NULL, allrows = FALSE, ...)

## S3 method for class 'baseline_term'
design_matrix(x, blockid = NULL, allrows = FALSE, ...)

## S3 method for class 'event_model'
design_matrix(x, blockid = NULL, ...)

## S3 method for class 'event_term'
design_matrix(x, drop.empty = TRUE, ...)

## S3 method for class 'fmri_model'
design_matrix(x, blockid = NULL, ...)

Arguments

x

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

...

Additional arguments passed to methods

blockid

Numeric vector specifying which blocks/runs to include (optional)

allrows

Logical; if TRUE, return all rows including those with no events (default: FALSE)

drop.empty

Logical; if TRUE, drop empty conditions (default: TRUE)

Details

Column Naming (Post-Refactor)

As of version X.Y.Z, column names in the final design matrix generated by event_model follow the structure: term_tag + ⁠_⁠ + condition_tag + ⁠_b##⁠ basis suffix

Refer to event_model documentation for details on term_tag and condition_tag generation. The design_matrix methods for individual term types (like design_matrix.event_term) return unconvolved predictors whose names may not yet follow this final structure. The final naming is applied by convolve.event_term and assembled by build_event_model_design_matrix.

Value

A tibble containing the design matrix, where:

  • Rows represent time points (scans)

  • Columns represent predictor variables

  • Column names indicate the condition or regressor (see Details)

Methods (by class)

  • design_matrix(afni_hrf_convolved_term): Design matrix for AFNI-convolved terms

    AFNI-convolved terms rely on AFNI software for design matrix construction. This method stops with an informative message.

See Also

event_model(), baseline_model(), fmri_model()


bbuchsbaum/fmrireg documentation built on June 10, 2025, 8:18 p.m.