2023-09-12 @Atsushi Kawaguchi
The mand
package provides functions for multivariate
analysis for neuroimaging data.
library(mand)
## Loading required package: msma
One subject image as the template is available in the mand package. The coad to load it is as follows.
data(template)
The image is compressed because of storage and computation time. The dimension is confirmed as follows.
dim(template)
## [1] 30 36 30
The image is plotted by the coat
function.
coat(template)
Other options with the plane argument (such as “axial,” “coronal,”
“sagittal,” and “all”) are available. The default setting is “axial”. If
the argument is specified as plane="all"
, three directional
slices at a certain coordinate are plotted.
coat(x=template, plane="all")
The imgdatamat
function reads image files saved in the
nifti format and creates data matrix with subjects in row and voxel in
column (this example does not work).
fnames1 = c("data1.nii", "data2.nii")
imgmat = imgdatamat(fnames1, simscale=1/4)
The first argument is file names with the length equaling the number
of subjects (the number of rows in the resulting data matrix). The
second argument simscale
is the image resize scale. In this
example, the all sizes (number of voxel) for three direction was reduced
into its quarter size. The output is the list form where the “S” is data
matrix, the “brainpos” is a binary image indicating brain region, and
the “imagedim” is image dimension. The ROI (Region Of Interest) volume
is computed in the “roi” if the ROI argument is TRUE.
imgmat = imgdatamat(fnames1, schange=TRUE, simscale=1/4, ROI=TRUE)
The resulting map from the statistical analysis such as the t
statistics map from the SPM is represented with overlapping on the
template. For example, the mand
package has the average
difference assuming Alzheimer’s disease and healthy subjects with the
array format.
The overlay is implemented by the coat
function.
data(diffimg)
coat(template, diffimg)
Anatomical brain segmentation region is useful for the plot and the interpretation. For example, the Automated Anatomical Labeling (AAL) atlas is used. The data.frame has two columns (“ROIid” and “ROIname”) format.
data(atlasdatasets)
atlasname = "aal3"
atlasdataset = atlasdatasets[[atlasname]]
head(atlasdataset)
## ROIid ROIname
## 1 1 Left Precentral gyrus
## 2 2 Right Precentral gyrus
## 3 3 Left Superior frontal gyrus-dorsolateral
## 4 4 Right Superior frontal gyrus-dorsolateral
## 5 5 Left Middle frontal gyrus
## 6 6 Right Middle frontal gyrus
It is also neccesary to prepare the array data.
data(atlas)
tmpatlas = atlas[[atlasname]]
dim(tmpatlas)
## [1] 30 36 30
It has the ROIid as the element.
tmpatlas[,15:20,12]
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 0 0 0 0 0 0
## [2,] 0 0 0 0 0 0
## [3,] 90 90 90 90 90 90
## [4,] 94 94 90 90 90 90
## [5,] 94 94 90 90 90 90
## [6,] 94 90 90 90 90 90
## [7,] 94 0 0 0 90 90
## [8,] 0 0 0 0 0 0
## [9,] 60 44 42 42 42 0
## [10,] 60 44 42 42 42 42
## [11,] 44 44 42 42 42 42
## [12,] 44 44 44 0 0 42
## [13,] 52 0 0 0 0 0
## [14,] 100 0 0 162 162 164
## [15,] 114 0 0 166 166 0
## [16,] 0 0 0 0 0 0
## [17,] 99 0 0 165 0 0
## [18,] 101 101 0 163 163 163
## [19,] 43 0 0 0 0 41
## [20,] 0 43 41 41 41 41
## [21,] 43 43 41 41 41 41
## [22,] 43 43 41 41 41 41
## [23,] 0 0 0 0 0 0
## [24,] 93 0 0 0 0 0
## [25,] 93 0 0 89 89 89
## [26,] 93 89 89 89 89 89
## [27,] 89 89 89 89 89 89
## [28,] 89 89 89 89 89 89
## [29,] 0 89 89 89 89 0
## [30,] 0 0 0 0 0 0
The anatomical region can be plotted by the coat
function with regionplot=TRUE.
coat(template, tmpatlas, regionplot=TRUE,
atlasdataset=atlasdataset, ROIids = c(1:2, 41:44), regionlegend=TRUE)
The resulting map can be converted into the summary of the anatomical regions.
atlastable(tmpatlas, diffimg, atlasdataset, ROIids = c(1:2, 41:44))
## ROIid ROIname sizepct sumvalue Min. Mean Max.
## 41 41 Left Hippocampus 0.591 -7.190 -1.000 0 0.448
## 42 42 Right Hippocampus 0.733 -12.110 -0.968 0 0.505
## 43 43 Left Parahippocampal gyrus 0.732 -5.495 -0.875 0 0.530
## 1 1 Left Precentral gyrus 0.617 8.300 -0.568 0 0.802
## 44 44 Right Parahippocampal gyrus 0.692 -3.147 -0.750 0 0.690
## 2 2 Right Precentral gyrus 0.632 -0.305 -0.735 0 0.750
The outputs are the number of voxel in the sizenum
column, the percentage of the voxel in the sizepct
column,
and the minimum, mean, and maximum valued of the region of the
overlaying map. The order of the table row is in the larger absolute
value of the minimum or maximum values.
The brain image corresponding to the region of interest can be extracted as follows. First, we create a mask image in which the hippocampal region is represented by 1 and others by 0. Then the product of the template and the mask image is taken for each voxel.
hipmask = (tmpatlas == 41) + (tmpatlas == 42)
template2 = template * hipmask
The images generated by these processes are plotted from left to right in one slice.
par(mfrow=c(1,3), mar=rep(1,4))
coat(template, pseq=12, paron=FALSE)
coat(hipmask, pseq=12, paron=FALSE)
coat(template2, pseq=12, paron=FALSE)
The template image (left) and the mask image (middle) are multiplied voxel by voxel to obtain the only hippocampus region image (right).
The sum of the voxel values in the region is calculated as follows.
sum(template[which(hipmask==1, arr.ind = TRUE)])/1000
## [1] 0.07090703
Such a value is calculated for each region and a dataset with ROI values is created.