correlation_map: correlation_map

View source: R/all_generic.R

correlation_mapR Documentation

correlation_map

Description

Generate a correlation heatmap showing the relationships between columns in a design matrix. This visualization helps identify potential collinearity between regressors in the model. For event models, it shows correlations between different conditions. For baseline models, it shows correlations between drift and nuisance terms.

Usage

correlation_map(x, ...)

Arguments

x

The model object (event_model, baseline_model, or fmri_model)

...

Additional arguments passed to methods. Common arguments include:

method

Correlation method ("pearson" or "spearman")

half_matrix

Logical; if TRUE, show only lower triangle

absolute_limits

Logical; if TRUE, set color limits to [-1,1]

Details

Create a correlation heatmap for an fMRI design matrix.

Value

A ggplot2 object containing the correlation heatmap, where:

  • Rows and columns represent model terms

  • Colors indicate correlation strength (-1 to 1)

  • Darker colors indicate stronger correlations

See Also

event_model(), baseline_model()

Examples

# 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
evmodel <- event_model(
  onsets ~ hrf(condition) + hrf(rt),
  data = event_data,
  block = ~run,
  sampling_frame = sframe
)

# Plot correlation map for event model
correlation_map(evmodel)

# Create baseline model
bmodel <- baseline_model(
  basis = "bs",
  degree = 3,
  sframe = sframe
)

# Plot correlation map for baseline model
correlation_map(bmodel)

# Create full model and plot combined correlations
fmodel <- fmri_model(evmodel, bmodel)
correlation_map(fmodel, method = "pearson", half_matrix = TRUE)

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