Learn R Programming

BayesBrainMap

R package BayesBrainMap implementing Bayesian brain mapping for individual functional topography and connectivity

This package contains functions implementing the BrainMap model proposed in Mejia et al. (2019) and the spatial BrainMap model proposed in proposed in Mejia et al. (2020+). (Previously, these models were named “Template ICA” and were contained in the package templateICAr.) For both models, subject-level brain networks are estimated as deviations from known population-level networks, which can be estimated using standard ICA algorithms or provided as a parcellation. Both models employ an expectation-maximization algorithm for estimation of the latent brain networks and unknown model parameters.

BrainMap consists of three steps. The main functions associated with each step are listed below.

  1. Prior estimation: estimate_prior. Can export the results with export_prior.
  2. BrainMap model estimation (single-subject): fit_BBM.
  3. Identification of areas of engagement in each network (or deviation from the prior mean): id_engagements.

Citation

If you use BayesBrainMap please cite the following papers:

NameAPA Citation
BrainMapMejia, A. F., Nebel, M. B., Wang, Y., Caffo, B. S., & Guo, Y. (2020). Template Independent Component Analysis: targeted and reliable estimation of subject-level brain networks using big data population priors. Journal of the American Statistical Association, 115(531), 1151-1177.
Spatial BrainMapMejia, A. F., Bolin, D., Yue, Y. R., Wang, J., Caffo, B. S., & Nebel, M. B. (2022). Template Independent Component Analysis with spatial priors for accurate subject-level brain network estimation and inference. Journal of Computational and Graphical Statistics, (just-accepted), 1-35.

You can also obtain citation information from within R like so:

citation("BayesBrainMap")

Installation

You can install the development version of BayesBrainMap from Github with:

# install.packages("devtools")
devtools::install_github("mandymejia/BayesBrainMap")

Important Notes on Dependencies:

To analyze or visualize CIFTI-format data, BayesBrainMap depends on the ciftiTools package, which requires an installation of Connectome Workbench. It can be installed from the HCP website.

For fitting the BrainMap model with surface-based priors (with spatial_model=TRUE in fit_BBM(), as is the default), INLA is required. Due to a CRAN policy, INLA cannot be installed automatically. You can obtain it by running install.packages("INLA", repos=c(getOption("repos"), INLA="https://inla.r-inla-download.org/R/stable"), dep=TRUE). Alternatively, dep=FALSE can be used along with manual installation of dependencies as necessary to avoid installing all of the many INLA dependencies, most of which are not actually required. Binaries for alternative Linux builds can be added with the command inla.binary.install(). Note that INLA is not required for standard BrainMap (with spatial_model=FALSE in fit_BBM()).

Depending on the analysis, PARDISO may reduce computation time. To obtain a free academic license forINLA-PARDISO, run inla.pardiso() in R after running library(INLA). Provide an academic email address. Once you obtain a license, point to it using INLA::inla.setOption(pardiso.license = "pardiso.lic") followed by INLA::inla.pardiso.check() to ensure that PARDISO is successfully installed and running.

Copy Link

Version

Install

install.packages('BayesBrainMap')

Monthly Downloads

136

Version

0.2.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Amanda Mejia

Last Published

February 3rd, 2026

Functions in BayesBrainMap (0.2.0)

estimate_prior_FC_empirical

Estimate empirical FC prior
export_prior

Export prior
fit_BBM

Bayesian brain mapping
estimate_prior_from_DR_two

Estimate prior from DR estimates (when there are two measurements)
make_mesh

Make INLA mesh from "surf" object
getInvCovAR

Compute inverse covariance matrix for AR process (up to a constant scaling factor)
estimate_prior_from_DR

Estimate prior from DR
get_FORMAT

Get FORMAT from format
halflogdetX

Half log determinant
hpf_param

hpf
format_engagement_name

Format engagement name
estimate_prior_FC_IW

Estimate IW FC prior
id_engagements

Engagements of (spatial) Bayesian brain mapping
orthonorm

Orthonormalizes a square, invertible matrix
make_mesh_2D

Make 2D INLA mesh
norm_BOLD

Normalize BOLD data
plot.prior.gifti

Plot prior
pw_estimate

Estimate residual autocorrelation for prewhitening
plot.prior.cifti

Plot prior
lik

Compute likelihood in SPDE model for ESS estimation
removebs_prior

Remove brain structure from CIFTI prior
make_Pmat

Make permutation matrix
make_mask

Create a mask based on vertices that are invalid
plot.bMap_eng.cifti

Plot engagements
loglik_kappa_est

Kappa log-likelihood
plot.bMap.nifti

Plot prior
struct_prior

Apply data structure to priors
plot.prior.matrix

Plot prior
plot.prior.nifti

Plot prior
summary.bMap.cifti

Summarize a "bMap.cifti" object
summary.prior.nifti

Summarize a "prior.nifti" object
summary.bMap.matrix

Summarize a "bMap.matrix" object
summary.bMap.nifti

Summarize a "bMap.nifti" object
summary.bMap_eng.matrix

Summarize a "bMap_eng.matrix" object
summary.prior.matrix

Summarize a "prior.matrix" object
scale_Param

scale
update_A

Update A for VB FC Bayesian brain mapping using IW prior on FC
summary.prior.gifti

Summarize a "prior.gifti" object
summary.bMap_eng.cifti

Summarize a "bMap_eng.cifti" object
summary.prior.cifti

Summarize a "prior.cifti" object
var_sq_err_constrained

Compute the overall error between empirical and theoretical variance of CORRELATION matrix elements
var_sq_err

Compute the error between empirical and theoretical variance of covariance matrix elements
summary.bMap_eng.nifti

Summarize a "bMap_eng.nifti" object
rm_nuisIC

Remove nuisance ICs from data
resample_prior

Resample CIFTI prior
plot.bMap.cifti

Plot fit_BBM estiamte
plot.bMap.matrix

Plot prior
update_tau2

Update tau for VB FC Bayesian brain mapping
update_S

Update S for VB FC Bayesian brain mapping
varTol_Param

varTol
update_A_Chol

Update A for VB FC Bayesian brain mapping using Cholesky prior for FC
sqrt_XtX

Compute matrix square root of X'X
IW_var_cor

Compute theoretical Inverse-Wishart variance of correlation matrix elements
LL_SQUAREM

Log-likelihood SQUAREM
BrainMap

BrainMap
IW_var

Compute theoretical Inverse-Wishart variance of covariance matrix elements
Chol_samp_fun

Cholesky-based FC sampling
EM_BBM.spatial

EM Algorithms for Bayesian brain maps
UpdateTheta_BBM

Parameter Estimates in EM Algorithm for Bayesian brain map
bdiag_m2

Bdiag m2
estimate_prior

Estimate prior
estimate_nu_matrix

Estimate IW dof parameter nu based on method of moments
estimate_nu

Universally estimate IW dof parameter nu based on method of moments, so that no empirical variance is under-estimated
TR_param

TR
Q2_max_check

Check Q2_max
UpdateThetaSQUAREM_BBM

Update theta SQUAREM
INLA_check

Check for INLA
compute_mu_s

Compute posterior mean and precision of s
VB_FC_BBM

VB_FC_BBM
dim_reduce

PCA-based Dimension Reduction and Prewhitening
estimate_prior_FC_Chol

Estimate Cholesky FC prior
GSR_Param

GSR
compute_LL_std

Compute LL for EM Bayesian brain mapping
compute_R_inv

Compute SPDE and prior precision matrices for S
LL2_kappa

Compute part of kappa log-likelihood
check_req_ifti_pkg

Check required packages for the data format
add_str

Combine additive terms in string
engagements

engagements
bdiag_m

Block diagonal matrix
check_parallel_packages

Check for required parallel packages
dual_reg2

Dual Regression wrapper
estimate.ESS

Estimation of effective sample size