split_reduce-methods: Summarize Subsets of an Object by Splitting by Row and...

split_reduceR Documentation

Summarize Subsets of an Object by Splitting by Row and Applying a Summary Function

Description

This function summarizes subsets of a numeric matrix or matrix-like object by first splitting the object by row and then applying a summary function.

Implementation of split_reduce for matrix with integer factors. See split_reduce for the generic definition and complete documentation.

Implementation of split_reduce for matrix with factor grouping. See split_reduce for the generic definition and complete documentation.

Implementation of split_reduce for matrix with factor grouping. See split_reduce for the generic definition and complete documentation.

Implementation of split_reduce for NeuroVec objects. See split_reduce for the generic definition and complete documentation.

Implementation of split_reduce for NeuroVec objects. See split_reduce for the generic definition and complete documentation.

Usage

split_reduce(x, fac, FUN)

## S4 method for signature 'matrix,integer,function'
split_reduce(x, fac, FUN)

## S4 method for signature 'matrix,factor,missing'
split_reduce(x, fac)

## S4 method for signature 'matrix,factor,function'
split_reduce(x, fac, FUN)

## S4 method for signature 'NeuroVec,factor,function'
split_reduce(x, fac, FUN)

## S4 method for signature 'NeuroVec,factor,missing'
split_reduce(x, fac, FUN)

Arguments

x

A NeuroVec object

fac

Factor for grouping

FUN

Function to apply to each group

Details

If 'FUN' is supplied, it must take a vector and return a single scalar value. If it returns more than one value, an error will occur.

If 'x' is a NeuroVec instance, voxels (dimensions 1:3) are treated as columns and time-series (dimension 4) as rows. The summary function is then applied to groups of voxels. However, if the goal is to apply a function to groups of time-points.

This method supports two types of splitting:

  • By voxel: when length(fac) equals number of voxels

  • By volume: when length(fac) equals number of volumes

This method supports two types of splitting:

  • By voxel: when length(fac) equals number of voxels

  • By volume: when length(fac) equals number of volumes

Value

A new matrix where the original values have been "reduced" by the supplied function.

Matrix of reduced values

Matrix of reduced values

Matrix of reduced values

Matrix of reduced values

Matrix of reduced values

See Also

split_reduce

split_reduce

split_reduce

split_reduce

split_reduce

Examples

mat = matrix(rnorm(100*100), 100, 100)
fac = factor(sample(1:3, nrow(mat), replace=TRUE))
## Compute column means of each sub-matrix
ms <- split_reduce(mat, fac)
all.equal(row.names(ms), levels(fac))

## Compute column medians of each sub-matrix
ms <- split_reduce(mat, fac, median)

## Compute time-series means grouped over voxels.
## Here, 'length(fac)' must equal the number of voxels: 'prod(dim(bvec)[1:3])'
bvec <- NeuroVec(array(rnorm(24*24*24*24), c(24,24,24,24)), NeuroSpace(c(24,24,24,24), c(1,1,1)))
fac <- factor(sample(1:3, prod(dim(bvec)[1:3]), replace=TRUE))
ms <- split_reduce(bvec, fac)
ms2 <- split_reduce(bvec, fac, mean)
all.equal(row.names(ms), levels(fac))
all.equal(ms, ms2)


bbuchsbaum/neuroim2 documentation built on Jan. 2, 2025, 3:38 p.m.