BayesFactorFMRI is a tool developed with R and Python to allow neuroimaging researchers to conduct Bayesian second-level analysis and Bayesian meta-analysis of fMRI image data with multiprocessing. This tool expedites computationally intensive Bayesian fMRI analysis through multiprocessing. Its GUI allows researchers who are not experts in computer programming to feasibly perform Bayesian fMRI analysis. BayesFactorFMRI is available via Zenodo and GitHub for download. It would be widely reused by neuroimaging researchers who intend to analyse their fMRI data with Bayesian analysis with better sensitivity compared with classical analysis while improving performance by distributing analysis tasks into multiple processors.

BayesFactorFMRI is a tool developed with R and Python to allow neuroimaging researchers to conduct Bayesian second-level analysis and Bayesian meta-analysis of fMRI data with multiprocessing [

However, there is a significant practical limitation in implementing Bayesian analysis in the context of neuroimaging. As the previous studies presented [

In order to address the aforementioned limitation of Bayesian fMRI analysis, a multiprocessing implementation of the Bayesian method in BayesFactorFMRI was attempted. Given that each fMRI image file consists of up to nine hundred thousand voxels to be tested, it would be possible to improve performance by assigning the voxels to multiple processors. BayesFactorFMRI uses NIfTI (.nii) or ANALYZE (.img + .hdr) image files as input files. For Bayesian second-level analysis, contrast images files that are created from first-level analysis performed by other fMRI analysis tools (e.g., SPM, FSL, AFNI) can be used for inputs. Moreover, to determine how many voxels are tested, a mask file that specify voxels to be tested is also used as an input. For Bayesian meta-analysis, statistical images from previous fMRI studies that report

In addition to the parallelization of Bayesian analysis, BayesFactorFMRI provides users with a graphical user interface (GUI; see

BayesFactorFMRI GUI. Top: GUI for Bayesian second-level analysis. Bottom: GUI for Bayesian meta-analysis.

The performances of Bayesian second-level analysis and meta-analysis were tested on the University of Alabama High-Performance Computing System (UAHPC; hardware and software specifications are described at

A tutorial example of Bayesian second-level analysis with BayesFactorFMRI. Left: The original image with true signals (blue: true positives). Middle: A sample of analysed images with original and noise signals. Right: The result of analysis when BFs.nii is thresholded with a Bayes factor threshold ≥3 (black: survived voxels).

In the case of Bayesian meta-analysis, 2, 4, 8, 16, 32, and 64 processors were used. To test the performance of Bayesian meta-analysis, six NIfTI images that were created in previous fMRI studies that examined the neural correlates of the working memory were analyzed. These six images were downloaded from NeuroVault (

A tutorial example of Bayesian meta-analysis with BayesFactorFMRI. Left: Six statistics images that are used for meta-analysis. Right: The result of Bayesian meta-analysis when BFs.nii is thresholded with the Bayes Factor threshold ≥3. Only survived voxels are presented.

When the performances of Bayesian second-level analysis and meta-analysis with multiprocessing were tested, the increase of the number of employed processors resulted in the improved performance in terms of the decrease in the elapsed time.

Changes in performance in terms of the elapsed time as a function of the number of employed processes. Top: Bayesian second-level analysis. Bottom: Bayesian meta-analysis.

The overall organization of BayesFactorFMRI is presented in

Organization of BayesFactorFMRI.

When run_this.py is executed, a Python code that distributes voxels into different processors is called. In the case of Bayesian second-level analysis, “bayes_correction_main.py” is called, and in the case of Bayesian meta-analysis, “bmeta_main.py” is called. Both Python codes assign voxels into the designated number of processors so that workloads are evenly distributed to the processors. Then, R codes for the intended statistical analysis are called. By using “popen” in subprocess, the R codes are called multiple times according to the number of processors.

First, Bayesian second-level analysis is performed after adjusting the prior probability distribution to address multiple comparisons. This adjustment process occurs before multiprocessing is initiated. The prior probability, which follows the Cauchy distribution, is adjusted according to how many voxels are tested (performed by correct_scale.R). The number of voxels to be tested is specified by a mask image in NIfTI. Then, “popen” creates multiple processes to distribute voxels into different professors. Bayesian one-sample

Second, Bayesian meta-analysis performed by performing random-effect meta-analysis of effect size values reported in previous studies in each voxel (fmri_bmeta_random1.R). At the beginning, “popen” calls multiple “fmri_bmeta_random1.R” to distribute voxels into the designated number of processors for multiprocessing. The effect size value in each voxel in each reported previous study is standardized. Then, Bayesian random-effect meta-analysis is performed at each voxel to examine whether there is a significant non-zero effect. Similar to the case of Bayesian second-level analysis, the analysis result in all voxels are integrated into whole-brain NIfTI image files. Three output images files, one reporting Bayes factors, one reporting mean effect size values, one reporting median effect size values, are created.

Both Bayesian second-level analysis and meta-analysis implemented in BayesFactorFMRI can be tested with tutorial datasets shared in GitHub (see

Once “run_this.py” is executed, it calls R codes for either Bayesian second-level analysis or meta-analysis following the selected option. At the end of the analysis process, NIfTI files reporting analysis outcomes are created. When BayesFactorFMRI is executed successfully, users should be able to see two (in the case of Bayesian second-level analysis) or three (in the case of Bayesian meta-analysis) created NIfTI output files. In the case of Bayesian second-level analysis “BFs.nii” and “Ds.nii” are created. “BFs.nii” reports the resultant Bayes factor value and “Ds.nii” reports the median effect size value in Cohen’s

When the analysis is properly done with the provided tutorial dataset, if “BFs.nii” is thresholded with xjView plus MATLAB with a Bayes factor threshold ≥ 3, the result of Bayesian second-level analysis should be similar to

BayesFactorFMRI has been developed and tested on macOS Mojave (not tested on Catalina at this point) and Centos 7. Given that BayesFactorFMRI has been developed with R and Python, it can be executed on macOS, Linux, or Windows with compatible R and Python environments.

R (>=3.5) and Python (>=3.7.3; Python 3.8 is not recommended due to package-related issues at this point). Developed and tested on R 3.5 and Python 3.7.3.

R: BayesFactor (developed with 0.9.12-4.2), metaBMA (developed with 0.6.1), oro.nifti (developed with 0.9.1).

Python: tkinter (developed with 8.6), shutil, pandas (developed with 0.24.2), nibabel (developed with 2.4.1), rpy2 (developed with 3.2.2), numpy (developed with 1.16.2), nilearn (developed with 0.6.2), subprocess.

Specified directions about how to install required dependencies are available in

Hyemin Han developed the software and created tutorials.

English

BayesFactorFMRI is available via Zenodo and GitHub with tutorial datasets and directions. Given that it provides its potential users, neuroimaging researchers in particular, with the GUI, they will be able to perform Bayesian second-level analysis and meta-analysis with their fMRI dataset feasibly even without expertise in Python and R programming. Because BayesFactorFMRI is a tool to analyse functional neuroimaging data, it cannot analyse other types of images, such as anatomical brain images, spine or other soft medical/biological tissue images. In the current version, for Bayesian second-level analysis, only a simple one-sample t-test is supported. Overall, because BayesFactorFMRI is distributed via open repositories and a tutorial with testable image files and directions are available for users, it will be widely and straightforwardly reused by neuroimaging researchers who intend to apply Bayesian analysis with enhanced sensitivity and performance through multiprocessing.

Any bugs, errors, questions, or suggestions associated with BayesFactorFMRI can be submitted via the “Issues” tab in the GitHub repository. Furthermore, the author, Hyemin Han, can be contacted via email (

The author thanks Joonsuk Park and Ian M. McDonough for their comments on this work.

The author has no competing interests to declare.