-
Notifications
You must be signed in to change notification settings - Fork 6
3. R package
The latest developer version of pTFCE can always be installed from GitHub:
Step 1. To be able to install pTFCE R-package from GitHub, first make sure you have the devtools package installed.
Type the followings into the R console to install and load devtools:
install.packages("devtools")
library(devtools)
install_github("spisakt/pTFCE@v0.1.0")
Make sure to change the version number after the @ sign to the latest one (or the preferred one) from the releases. Then load the installed package:
library(pTFCE)
citation("pTFCE")
Now, you are ready for cluster-based belief boosting!
pTFCE will be soon also available on CRAN...
Installing pTFCE automatically installed its dependencies, the mmand and the oro.nifti R-packages. The latter one is needed to read NIfTI files. We must load it, and also the pTFCE package:
library(oro.nifti)
library(pTFCE)
- in FSL this will be something like <your_gfeat_folder>/cope.feat/stats/zstat.nii.gz
- in SPM, by default you have only your T-score map, called spmT_.nii (or .hdr/.img pair) at hand. In R, after loading this image with "readNIfTI" (see below) you can convert it to a Z-score map by the command "Z=qnorm( pt(Tmap, df=degrees_of_freedom, log.p = T), log.p = T )", where your degrees-of-freedom can be found in your SPM.mat.
- or you can download and use this simulated sample file to continue with this tutorial: https://github.com/spisakt/pTFCE/blob/master/data/example.nii.gz
Z=readNIfTI("path/to/your/z-score-map.nii.gz")
- in FSL this will be something like <your_feat_folder>/mask.nii.gz
- in SPM this will be the file called mask.nii (or .hdr/.img pair) in your SPM analysis folder.
- or you can download and use this simulated sample file to continue with this tutorial: http://github.com/spisakt/pTFCE/blob/master/data/test02_mask.nii.gz
MASK=readNIfTI("path/to/your/mask.nii.gz")
pTFCE=ptfce(Z, MASK)
Now, the enhanced image is in the returned pTFCE object. E.g. the enhanced Z-score map is available as pTFCE$Z.
Let's compare the pTFCE enhanced image to the original one:
orthographic(Z, zlim=c(0, max(pTFCE$Z)), crosshair=F)
#original
orthographic(pTFCE$Z, zlim=c(0, max(pTFCE$Z)), crosshair=F)
#pTFCE
In case you used the simulated sample files, you should see something like:
Alternatively, you can save the enhanced image as NIfTI with:
writeNIfTI(pTFCE$Z, "path/to/your/pTFCE-z-score-map.nii.gz")
And use your favourite NIfTI image viewer.
In general, it is approximately valid to threshold your enhanced Z-score image with the same Z-score threshold you would have applied for the original (unenhanced) Z-score image. E.g. you can threshold the enhanced Z-score image for an uncorrected p<0.001 with the corresponding Z-score value of Z>3.1. Or you can perform a correction for multiple comparisons on the original (unenhanced) Z-score map via controlling for the family-wise error rate, then get the Z-threshold and use it on the pTFCE-enhanced Z-score image.
Never use the enhanced Z-score map as an input for GRF-based multiple correction techniques. Instead, use the original Z-score map to compute the Z-score threshold and then use this threshold on the enhanced image.
The pTFCE R-package also provides some functionality to perform image thresholding with GRF theory-based multiple comparison.
To apply the common p<0.05 corrected statistical threshold, simply use the 'fwer0.05.Z' field of the ptfce output:
orthographic(pTFCE$Z, zlim=c(pTFCE$fwer0.05.Z, max(pTFCE$Z)), crosshair=F)
This displays the pTFCE enhanced Z-score image thresholded at p<0.05, corrected for multiple comparisons via GRF Theory-based maximum height thresholding.
To apply corrected p-value threshold other than 0.05, you might also consider using the fwe.p2z() and fwe.z2p() functions of the pTFCE R-package.
fwer0.01.Z=fwe.p2z(pTFCE$number_of_resels, 0.01)
orthographic(pTFCE$Z, zlim=c(fwer0.01.Z, max(pTFCE$Z)), crosshair=F)
Tamás Spisák, Zsófia Spisák, Matthias Zunhammer, Ulrike Bingel, Stephen Smith, Thomas Nichols, Tamás Kincses, Probabilistic TFCE: a generalised combination of cluster size and voxel intensity to increase statistical power. Neuroimage, 185:12-26. DOI: 10.1016/j.neuroimage.2018.09.078