Learn R Programming

EMC2 (version 3.2.0)

reshape_events: Reshape events data for fMRI analysis

Description

This function reshapes event data into a format suitable for fMRI analysis by converting specified event_types into separate event types with appropriate modulation values.

Usage

reshape_events(events, event_types, duration = 0.001, modulation = NULL)

Value

A data frame with columns 'subjects', 'onset', 'run', 'modulation', 'duration', and 'event_type'

Arguments

events

A data frame containing event information with required columns 'subjects', 'run', and 'onset'

event_types

A character vector of column names in the events data frame to be treated as event_types

duration

Either a single numeric value (applied to all event_types), a list with named elements corresponding to event_types, or a function that takes the events data frame and returns durations

modulation

Either a list with named elements corresponding to event_types, or a function that takes the events data frame and returns durations

Examples

Run this code
# Create a simple events data frame
events <- data.frame(
  subjects = rep(1, 10),
  run = rep(1, 10),
  onset = seq(0, 90, by = 10),
  condition = rep(c("A", "B"), 5),
  rt = runif(10, 0.5, 1.5),
  accuracy = sample(0:1, 10, replace = TRUE)
)

# Reshape with default duration
reshaped1 <- reshape_events(events, event_types = c("condition", "accuracy"))

# Reshape with custom duration for each event_type
reshaped2 <- reshape_events(events,
                           event_types = c("condition", "accuracy", "rt"),
                           duration = list(condition = 0.5,
                                          accuracy = 0.2,
                                          rt = function(x) x$rt))

Run the code above in your browser using DataLab