regressProjections.Rd
Perform regression on a training set of images, projected onto (provided) eigenvectors, and test on testing images.
regressProjections(
input.train,
input.test,
demog.train,
demog.test,
eigenvectors,
mask,
outcome,
covariates = "1",
model.function = glm,
which.eigenvectors = "all",
...
)
Masked imaging data from training set of type
antsImage
or matrix
. This will typically be read from a
train.mha
file generated by, e.g., sccan --imageset-to-matrix
.
Masked imaging data from testing set of type
antsImage
or matrix
. This will typically be read from a
test.mha
file generated by, e.g., sccan --imageset-to-matrix
.
Data frame of demographics information for training images.
Data frame of demographics information for testing images.
List of eigenvector images for dimensionality reduction.
Mask image of type antsImage
.
Name of outcome variable to be predicted. Must be present in
demog.train
and demog.test
.
List of names of covariates to be used for the prediction.
All names must be present in demog.train
and demog.test
.
Modeling function for predicting outcome from input
data. Can be any function that has formula
and data
arguments
and a predict
method. Defaults to glm
, but svm, randomForest,
etc. will also work (assuming necessary libraries are loaded).
Method for selecting eigenvectors. Can be either
'all'
(uses all eigenvectors in vector.names
) or
'optimal'
(uses BIC stepwise model selection to select eigenvectors).
'optimal'
only works for model.function
arguments that include
an extractAIC
method and a coefficients
attribute.
Additional arguments for input to model.function
. Example
input would be family=binomial
for classification instead of
regression when using glm
.
A list of diagnostic and statistical information generated from the
prediction, including: stats
: Statistics on computed fits. For
numeric outcomes, mean squared error, correlation coefficients, and p-value
of prediction for training and testing data. For factor outcomes,
misclassification rate and p-value of classification model.
outcome.comparison
: Data frame comparing real vs. predicted values
for testing data. eigenvectors
: List of eigenvectors retained in
model building.
regressProjections
is a convenient way to perform training and
testing of predictions of demographic information from imaging data. It
takes as input demographics information, imaging data, and eigenvectors, and
performs prediction of the outcome variable from the projection of the
imaging data on the eigenvectors.
# generate simulated outcome
nsubjects <- 100
x1 <- seq(1, 10, length.out = nsubjects) + rnorm(nsubjects, sd = 2)
x2 <- seq(25, 15, length.out = nsubjects) + rnorm(nsubjects, sd = 2)
outcome <- 3 * x1 + 4 * x2 + rnorm(nsubjects, sd = 1)
# generate simulated images with outcome predicted
# by sparse subset of voxels
voxel.1 <- 3 * x1 + rnorm(nsubjects, sd = 2)
voxel.2 <- rnorm(nsubjects, sd = 2)
voxel.3 <- 2 * x2 + rnorm(nsubjects, sd = 2)
voxel.4 <- rnorm(nsubjects, sd = 3)
input <- cbind(voxel.1, voxel.2, voxel.3, voxel.4)
# simulate eigenvectors and mask
mydecom <- sparseDecom(input, sparseness = 0.25, nvecs = 4)
mask <- as.antsImage(matrix(c(1, 1, 1, 1), nrow = 2))
# generate sample demographics that do not explain outcome
age <- runif(nsubjects, 50, 75)
demog <- data.frame(outcome = outcome, age = age)
# randomly divide data into training and testing
data.split <- splitData(demog, 2 / 3, return.rows = TRUE)
eanatimages <- matrixToImages(mydecom$eig, mask)
result <- regressProjections(
input[data.split$rows.in, ],
input[data.split$rows.out, ],
data.split$data.in, data.split$data.out,
eanatimages,
mask, "outcome"
)