sparseRegression¶
purpose:
Sparse regression on input images.
description:
Compute a sparse, spatially coherent regression from a set of input images (with mask) to an outcome variable.
usage:
sparseRegression(inmatrix, demog, outcome, mask=NA, sparseness=0.05, nvecs=50,
its=5, cthresh=250, statdir=NA, z=0, smooth=0)
examples:
nsubj <- 1000
prop.train <- 1/2
subj.train <- sample(1:nsubj, prop.train*nsubj, replace=F)
input <- t(replicate(nsubj, rnorm(125)))
outcome <- seq(1, 5, length.out=nsubj)
demog <- data.frame(outcome=outcome)
input[, 40:60] <- 30 + outcome + rnorm(length(input[, 40:60]), sd=2)
input.train <- input[subj.train, ]
input.test <- input[-subj.train, ]
demog.train <- data.frame(outcome=demog[subj.train, ])
demog.test <- data.frame(outcome=demog[-subj.train, ])
mymask <- as.antsImage(array(rep(1, 125), dim=c(5,5,5)))
myregression <- sparseRegression(input.train, demog.train, "outcome", mymask,
sparseness=0.05, nvecs=5, its=3, cthresh=250)
# visualization of results
sample <- rep(0, 125)
sample[40:60] <-1
signal.img <- as.antsImage(array(rep(0,125), dim=c(5, 5, 5)))
signal.img[signal.img >= 0 ] <- sample
plotANTsImage( signal.img, axis=2, slices="1x5x1") # actual source of signal
# compare against first learned regression vector
myimgs <- list()
for( i in 1:5){
myarray <- as.array(myregression$eigenanatomyimages[[ i ]])
myarray <- myarray / max(abs(myarray)) # normalize for visualization
myimgs[[ i ]] <- antsImageClone(myregression$eigenanatomyimages[[ i ]])
myimgs[[ i ]][mymask > 0] <- myarray
}
plotANTsImage(myimgs[[1]], axis=2, slices="1x5x1")
# use learned eigenvectors for prediction
result <- regressProjections(input.train, input.test, demog.train,
demog.test, myregression$eigenanatomyimages, mymask, "outcome")
plot(result$outcome.comparison$real, result$outcome.comparison$predicted)