matrix_dataset: Create a Matrix Dataset Object

View source: R/fmri_dataset.R

matrix_datasetR Documentation

Create a Matrix Dataset Object

Description

This function creates a matrix dataset object, which is a list containing information about the data matrix, TR, number of runs, event table, sampling frame, and mask.

Usage

matrix_dataset(datamat, TR, run_length, event_table = data.frame())

Arguments

datamat

A matrix where each column is a voxel time-series.

TR

Repetition time (TR) of the fMRI acquisition.

run_length

A numeric vector specifying the length of each run in the dataset.

event_table

An optional data frame containing event information. Default is an empty data frame.

Value

A matrix dataset object of class c("matrix_dataset", "fmri_dataset", "list").

Examples

# A matrix with 100 rows and 100 columns (voxels)
X <- matrix(rnorm(100*100), 100, 100)
dset <- matrix_dataset(X, TR=2, run_length=100)

# An iterator with 5 chunks
iter <- data_chunks(dset, nchunks=5)
`%do%` <- foreach::`%do%`
y <- foreach::foreach(chunk = iter) %do% { colMeans(chunk$data) }
length(y) == 5

# An iterator with 100 chunks
iter <- data_chunks(dset, nchunks=100)
y <- foreach::foreach(chunk = iter) %do% { colMeans(chunk$data) }
length(y) == 100

# A matrix_dataset with 200 rows, 100 columns and 2 runs
X <- matrix(rnorm(200*100), 200, 100)
dset <- matrix_dataset(X, TR=2, run_length=c(100,100))

# Get a "runwise" iterator. For every iteration, an entire run's worth of data is returned.
iter <- data_chunks(dset, runwise=TRUE)
y <- foreach::foreach(chunk = iter)  %do% { colMeans(chunk$data) }
length(y) == 2

bbuchsbaum/fmrireg documentation built on May 16, 2023, 10:56 a.m.