minc.apply {RMINC}R Documentation

Apply an arbitrary function to all voxels of a list of MINC files

Description

Similar to apply, this allows one to apply an arbitrary R function to a list of MINC2 volumes.

Usage

average <- minc.apply(filenames, quote(mean(x)), mask=mask.filename)

Arguments

filenames

A list of filenames of MINC2 volumes.

function.string

A string containing the function to be evaluated at every voxels. See details.

mask

An optional filename of a mask volume.

Details

This function allows for the evaluation of an arbitrary R function at every voxel of the input files. The function needs to take an argument named "x", which is an array of voxel values, and return an array of the same length. The examples ought to illustrate this somewhat better.

Examples

## Not run: 
# get a file that could be used by glim_image
gf <- as.data.frame(read.table("filename.glim"))

# get the mean of all files
means <- minc.apply(gf$V1, quote(mean(x)))

# run a linear model. Need to create a function first.
f <- function(x) {
  summary(lm(x ~ gf$V2))$coefficients[2,3]
}

# now apply to every voxel. This'll take a while ...
t.stats <- minc.apply(gf$V1, quote(f(x)))

# and write to file
minc.write.volume("t-test.mnc", gf$V1[1], t.stats)

## End(Not run)

[Package RMINC version 0.5.1 Index]