Learn R Programming

ANTsR (version 1.0)

vwnrfs: voxelwise neighborhood random forest segmentation and prediction

Description

Represents feature images as a neighborhood and uses the features to build a random forest prediction from an image population

Usage

vwnrfs(y, x, labelmask, rad = NA, nsamples = 1, ntrees = 500,
  asFactors = TRUE)

Arguments

y

list of training label images, can be a factor or numeric vector this can also be a regular old vector

x

a list of lists where each list contains feature images

labelmask

a mask for the features (all in the same image space) the labelmask defines the number of parallel samples that will be used per subject sample. two labels will double the number of predictors contributed from each feature image.

rad

vector of dimensionality d define nhood radius

nsamples

(per subject to enter training)

ntrees

(for the random forest model)

asFactors

boolean - treat the y entries as factors

Value

list a 4-list with the rf model, training vector, feature matrix and the random mask

Examples

Run this code
# NOT RUN {
mask<-makeImage( c(10,10), 0 )
mask[ 3:6, 3:6 ]<-1
mask[ 5, 5:6]<-2
ilist<-list()
lablist<-list()
inds<-1:50
scl<-0.33 # a noise parameter
for ( predtype in c("label","scalar") )
{
for ( i in inds ) {
  img<-antsImageClone(mask)
  imgb<-antsImageClone(mask)
  limg<-antsImageClone(mask)
  if ( predtype == "label") {  # 4 class prediction
    img[ 3:6, 3:6 ]<-rnorm(16)*scl+(i %% 4)+scl*mean(rnorm(1))
    imgb[ 3:6, 3:6 ]<-rnorm(16)*scl+(i %% 4)+scl*mean(rnorm(1))
    limg[ 3:6, 3:6 ]<-(i %% 4)+1  # the label image is constant
    }
    if ( predtype == "scalar") {
      img[ 3:6, 3:6 ]<-rnorm(16,1)*scl*(i)+scl*mean(rnorm(1))
      imgb[ 3:6, 3:6 ]<-rnorm(16,1)*scl*(i)+scl*mean(rnorm(1))
      limg<-i^2.0  # a real outcome
      }
    ilist[[i]]<-list(img,imgb)  # two features
    lablist[[i]]<-limg
  }
  rfm<-vwnrfs( lablist , ilist, mask, rad=c(2,2) )
  if ( predtype == "label" )
    print(  sum( rfm$tv != predict(rfm$rfm) ) )
  if ( predtype == "scalar" )
    print( cor(as.numeric(rfm$tv) , as.numeric(predict(rfm$rfm) ) ) )
} # end predtype loop
# }

Run the code above in your browser using DataLab