multiResRandomForestRegression: multiple resolution neighborhood random forest regression

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/multiResRandomForestRegression.R

Description

Represents feature images as a neighborhood across scales to build a random forest prediction from an image population. A use case for this function is to predict cognition from multiple image features, e.g. from the voxelwise FA of the corpus callosum and, in parallel, voxelwise measurements of the volume of the inferior frontal gyrus.

Usage

1
2
3
4
5
6
7
8
9
multiResRandomForestRegression(
  y,
  x,
  labelmasks,
  rad = NA,
  nsamples = 10,
  multiResSchedule = c(0),
  ntrees = 500
)

Arguments

y

vector of scalar values or labels. if a factor, do classification, otherwise regression.

x

a list of lists where each list contains feature images

labelmasks

a list of masks where each mask defines the image space for the given list and the number of parallel predictors. more labels means more predictors. alternatively, separate masks may be used for each feature in which case this should be a list of lists. see examples.

rad

vector of dimensionality d define nhood radius

nsamples

(per subject to enter training)

multiResSchedule

an integer vector defining multi-res levels

ntrees

(for the random forest model)

Value

list with a random forest model, a vector identifying which rows correspond to which subjects and a prediction vector.

Author(s)

Avants BB, Tustison NJ

References

Pustina, D, et al. Automated segmentation of chronic stroke lesions using LINDA: Lesion Identification with Neighborhood Data Analysis, Human Brain Mapping, 2016. (related work, not identical)

See Also

getMultiResFeatureMatrix mrvnrfs

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
mask<-makeImage( c(100,100), 0 )
mask[ 30:60, 30:60 ]<-1
mask[ 35:45, 50:60]<-2
ilist<-list()
masklist<-list()
inds<-1:8
yvec<-rep(0,length(inds))
scl<-0.33 # a noise parameter
for ( i in inds ) {
  img<-antsImageClone(mask)
  imgb<-antsImageClone(mask)
  limg<-antsImageClone(mask)
  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))
  ilist[[i]]<-list(img,imgb)  # two features
  yvec[i]<-i^2.0  # a real outcome
  masklist[[i]] = antsImageClone( mask )
  }
r=c(1,1)
mr=c(2,0)
featMat <- getMultiResFeatureMatrix( ilist[[1]], masklist[[1]],
  rad=r, , multiResSchedule=mr )
rfm <- multiResRandomForestRegression(
  yvec , ilist, masklist, rad=r, multiResSchedule=mr )
preds = predict( rfm, newdata=featMat )
## Not run: 
# data: https://github.com/stnava/ANTsTutorial/tree/master/phantomData
fns = Sys.glob("phantom*wmgm.jpg")
ilist = imageFileNames2ImageList( fns )
masklist = list( )
flist = list( )
for ( i in 1:length(fns) )
  {
# 2 labels means 2 sets of side by side predictors and features at each scale
  locseg = kmeansSegmentation( ilist[[i]], 2 )$segmentation
  masklist[[ i ]] = list( locseg, locseg %>% thresholdImage(2,2), locseg )
  flist[[ i ]] = list( ilist[[i]], ilist[[i]] %>% iMath("Laplacian",1),
    ilist[[i]] %>% iMath("Grad",1)  )
  }
yvec = factor( rep( c(1,2), each = 4 ) ) # classification
r = c( 1, 1 )
mr = c( 2, 1, 0 )
ns = 50
trn = c(1:3,6:8)
ytrain = yvec[ trn ]
ftrain = flist[ trn ]
mtrain = masklist[ trn ]
mrrfr = multiResRandomForestRegression( ytrain, ftrain, mtrain, rad=c(1,1),
  nsamples = ns, multiResSchedule=mr )
mypreds = rep( NA, length( fns ) )
mymode <- function(x) {
 ux <- unique(x)
 ux[which.max(tabulate(match(x, ux)))]
}
for ( i in 4:5 ) # test set
  {
  fmat = getMultiResFeatureMatrix( flist[[i]], masklist[[i]],
         rad=r,  multiResSchedule=mr, nsamples = ns )
  myp = predict( mrrfr, newdata=fmat )
  mypreds[ i ] = mymode( myp ) # get the most frequent observation
  # use median or mean for continuous predictions
  }
print("predicted")
print( mypreds[-trn] )
print("ground truth")
print( yvec[-trn] )

## End(Not run)

neuroconductor/ANTsR documentation built on Oct. 11, 2020, 8:14 a.m.