contrast_weights: Calculate contrast weights for a given contrast specification...

View source: R/all_generic.R

contrast_weightsR Documentation

Calculate contrast weights for a given contrast specification and term.

Description

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.).

Usage

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, ...)

Arguments

x

The contrast specification object

...

Extra arguments passed to specific methods

Value

A list containing:

term

The model term the contrast is applied to

name

The name of the contrast

weights

A matrix of contrast weights

condnames

The condition names associated with the weights

contrast_spec

The original contrast specification

See Also

pair_contrast(), unit_contrast(), poly_contrast()

Examples

# 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)

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