contrast_weights | R Documentation |
This function calculates the contrast weights based on the contrast specification provided by the user. It is a generic function that dispatches to the appropriate method depending on the class of the contrast specification (e.g., unit_contrast_spec, pair_contrast_spec, poly_contrast_spec, etc.).
contrast_weights(x, ...)
## S3 method for class 'convolved_term'
contrast_weights(x, ...)
## S3 method for class 'fmri_model'
contrast_weights(x, ...)
## S3 method for class 'event_model'
contrast_weights(x, ...)
x |
The contrast specification object |
... |
Extra arguments passed to specific methods |
A list containing:
The model term the contrast is applied to
The name of the contrast
A matrix of contrast weights
The condition names associated with the weights
The original contrast specification
pair_contrast()
, unit_contrast()
, poly_contrast()
# Create a data frame with experimental design
event_data <- data.frame(
condition = factor(c("A", "B", "A", "B")),
onsets = c(1, 10, 20, 80),
run = c(1, 1, 1, 1)
)
# Create a sampling frame
sframe <- sampling_frame(blocklens = 50, TR = 2)
# Create an event model
evmodel <- event_model(
onsets ~ hrf(condition),
data = event_data,
block = ~run,
sampling_frame = sframe
)
# Create a contrast comparing conditions A and B
con <- pair_contrast(
~condition == "A",
~condition == "B",
name = "A_vs_B"
)
# Calculate the contrast weights
weights <- contrast_weights(con, evmodel)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.