design_matrix | R Documentation |
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.
design_matrix(x, ...)
## S3 method for class 'event_model'
design_matrix(x, blockid = NULL, ...)
## S3 method for class 'convolved_term'
design_matrix(x, blockid = NULL, ...)
## S3 method for class 'matrix_term'
design_matrix(x, ...)
## S3 method for class 'fmri_model'
design_matrix(x, blockid = NULL, ...)
x |
The term or model object (typically an event_term, event_model, baseline_model, or fmri_model) |
... |
Additional arguments passed to methods. Common arguments include:
|
blockid |
the block id to extract |
Construct a design matrix from a term or model.
A tibble containing the design matrix, where:
Rows represent time points (scans)
Columns represent predictor variables
Column names indicate the condition or regressor
event_model()
, baseline_model()
, fmri_model()
# Create event data
event_data <- data.frame(
condition = 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(condition) + hrf(rt),
data = event_data,
block = ~run,
sampling_frame = sframe
)
# Get full design matrix
dmat <- design_matrix(evmodel)
# Get design matrix for specific block
block1_dmat <- design_matrix(evmodel, blockid = 1)
# Create and get baseline design matrix
bmodel <- baseline_model(basis = "bs", degree = 3, sframe = sframe)
bdmat <- design_matrix(bmodel)
# Get combined design matrix from full model
fmodel <- fmri_model(evmodel, bmodel)
full_dmat <- design_matrix(fmodel)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.