Description Usage Arguments Details Value Examples

Generic function to summarize subsets of an object by first splitting by row and then "reducing" by a summary `function`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ```
split_reduce(x, fac, FUN)
## S4 method for signature 'matrix,integer,'function''
split_reduce(x, fac, FUN)
## S4 method for signature 'matrix,integer,missing'
split_reduce(x, fac)
## 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)
``` |

`x` |
a numeric matrix(like) object |

`fac` |
the factor to define subsets of the object |

`FUN` |
the function to apply to each subset. if |

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 then voxels (dims 1:3) are treated as columns and time-series (dim 4) as rows.
The summary function then is applied to groups of voxels. However, if the goal is to apply a function to groups of time-points,
then this can be achieved as follows:

` split_reduce(t(as.matrix(bvec)), fac) `

a new `matrix`

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ```
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, \code{length(fac)} must equal the number of voxels: \code{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 Oct. 15, 2019, 2:55 p.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.