Learn R Programming

BayesfMRI

The BayesfMRI R package includes the main function BayesGLM, which implements a spatial Bayesian GLM for task fMRI. It also contains a wrapper function BayesGLM_cifti, for CIFTI cortical surface fMRI data.

Citation

If you use BayesfMRI please cite the following papers:

NameAPA Citation
Spatial Bayesian GLMMejia, A. F., Yue, Y., Bolin, D., Lindgren, F., & Lindquist, M. A. (2020). A Bayesian general linear modeling approach to cortical surface fMRI data analysis. Journal of the American Statistical Association, 115(530), 501-520.
Multi-session Spatial Bayesian GLMSpencer, D., Yue, Y. R., Bolin, D., Ryan, S., & Mejia, A. F. (2022). Spatial Bayesian GLM on the cortical surface produces reliable task activations in individuals and groups. NeuroImage, 249, 118908.

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

citation("BayesfMRI")

Installation

You can install BayesfMRI from CRAN with:

install.packages("BayesfMRI")

Vignette

See this link to view the tutorial vignette.

Important Note on Dependencies:

BayesfMRI depends on the ciftiTools package, which requires an installation of Connectome Workbench. It can be installed from the HCP website.

The INLA package is required, which, due to a CRAN policy, will not 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=FALSE). For more information, see the INLA website. Note: INLA must be installed before installing BayesfMRI.

On Mac platforms, an installation of Xcode is necessary to build the C++ code included in BayesfMRI.

Copy Link

Version

Install

install.packages('BayesfMRI')

Monthly Downloads

223

Version

0.10.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Amanda Mejia

Last Published

March 7th, 2025

Functions in BayesfMRI (0.10.1)

GLMEM_objfn

Objective function for the BayesGLM EM algorithm
GLM_classical

Classical GLM
Bayes_Param

Bayes
aic_Param

aic
activations.posterior

Identify activations using joint posterior probabilities
BayesGLM_session_names

Get session_names for GLM
design_Param_BayesGLM

design
SPDE_from_vertex

SPDE from mesh model
F.logwt

F logwt
BayesGLM_format_cifti

Format fit_bayesglm results into "xifti" objects
BayesGLM_format_scrub

Format scrub
SPDE_from_voxel

SPDE from voxel model
ar_order_Param

ar_order
BayesGLM

BayesGLM for CIFTI
ar_smooth_Param

ar_smooth
BayesGLM2

Group-level Bayesian GLM
beta.posterior.thetasamp

Beta posterior theta sampling
BayesGLM_argChecks

Bayes GLM arg checks
.getSqrtInvCpp

Get the prewhitening matrix for a single data location
brainstructures_Param_BayesGLM

brainstructures
BayesfMRI-package

BayesfMRI: Spatial Bayesian Methods for Task Functional MRI Studies
.initialKP

Find the initial values of kappa2 and phi
hpf_Param_BayesGLM

hpf
BayesGLM_is_valid_one_design

Is a valid design?
init_fixpt

The fix point function for the initialization of kappa2 and phi
make_replicates

Make replicates
field_names_Param

field_names
fit_bayesglm

fit_bayesglm
make_sqrtInv_all

Make sqrtInv_all
GLMEM_fixptseparate

Fixed point function for the joint BayesGLM EM update algorithm
dgCMatrix_cols_to_zero

Set column values to zero for sparse matrix
nbhd_order_Param

nbhd_order
INLA_Description

INLA
Connectome_Workbench_Description

Connectome Workbench
mesh_Param_either

mesh: either
mean_var_Tol_Param

mean and variance tolerance
get_nV

Get number of locations for various masks
galerkin_db

Create FEM matrices
INLA_Latent_Fields_Limit_Description

INLA Latent Fields
do_QC

Mask out invalid data
neg_kappa_fn

The negative of the objective function for kappa
scale_design_mat

Scale the design matrix
.findTheta

Perform the EM algorithm of the Bayesian GLM fitting
scrub_Param_BayesGLM

scrub
INLA_deps

Import INLA dependencies
BayesGLM_is_valid_one_scrub

Is a valid scrub?
BayesGLM_is_valid_one_nuisance

Is a valid nuisance?
log_kappa_tau

Make log_kappa and log_tau
validate_spatial

Validate spatial
Q_prime

Q prime
prep_kappa2_optim

Find values for coefficients used in objective function for kappa2
make_A_mat

Make A matrix
GLM_compare

Classical GLM for multiple models
GLM_est_resid_var_pw

Standardize data variance, and prewhiten if applicable
scale_BOLD

Scale the BOLD timeseries
prevalence

Activations prevalence.
scale_BOLD_Param

scale_BOLD
TrSigB

Hutchinson estimator of the trace
activations

Identify field activations
buffer_Param

buffer
TR_Param_BayesGLM

TR
TrQbb

Trace of Q beta' beta
contrasts_Param

contrasts
verbose_Param

verbose
TrQEww

Trace approximation function
extract_estimates

Extract Estimates of Activation
create_listRcpp

Function to prepare objects for use in Rcpp functions
.logDetQt

Find the log of the determinant of Q_tilde
check_INLA

Check INLA and PARDISO
activations.classical

Identification of areas of activation in a General Linear Model using classical methods
cholQsample

Sample from the multivariate normal distribution with Cholesky(Q)
cbind2

cbind if first argument might be NULL
summary.BGLM

Summarize a "BGLM" object
faces_Param

faces
plot.BGLM

S3 method: use view_xifti to plot a "BGLM" object
get_posterior_densities2

Extracts posterior density estimates for hyperparameters for volumetric SPDE
init_objfn

Objective function for the initialization of kappa2 and phi
get_posterior_densities

Extracts posterior density estimates for hyperparameters
plot.BGLM2

S3 method: use view_xifti to plot a "BGLM2" object
vertex_areas

Surface area of each vertex
summary.BGLM2

Summarize a "BGLM2" object
s2m_B

Sequential 2-means on array B
s2m

Sequential 2-means variable selection
vertices_Param

vertices
summary.fit_bglm

Summarize a "fit_bglm" object
make_mesh

Make Mesh
emTol_Param

emTol
make_data_list

Make data list for estimate_model
surfaces_Param_BayesGLM

surfaces
summary.fit_bglm2

Summarize a "fit_bglm2" object
mesh_Param_inla

mesh: INLA only
n_threads_Param

n_threads
mask_Param_vertices

mask: vertices
max_threads_Param

max_threads
qsample

Sample from a multivariate normal with mean and precision
neg_kappa_fn2

The negative of the objective function for kappa without Sig_inv
trim_INLA_Param

trim_INLA
pw_smooth

Smooth AR coefficients and white noise variance
neg_kappa_fn3

Streamlined negative objective function for kappa2 using precompiled values
intersect_mask

Intersection mask for BayesGLM or activations result
pw_estimate

Estimate residual autocorrelation for prewhitening
summary.act_BGLM

Summarize a "act_BGLM" object
resamp_res_Param_BayesGLM

resamp_res
is_matrix_or_df

Is a matrix or data.frame?
kappa_init_fn

Function to optimize over kappa2
return_INLA_Param

return_INLA
sparse_and_PW

Organize data for Bayesian GLM
retro_mask_mesh

Retroactively mask locations from mesh.
summary.act_fit_bglm

Summarize a "act_fit_bglm" object
make_Q

Make the full SPDE precision based on theta, the spde, and the number of sessions
neg_kappa_fn4

Streamlined negative objective function for kappa2 using precompiled values
unmask_Mdat2In

Unmask data
trim_INLA_model_obj

Trim INLA object
make_A_mat_rs

Make A matrix with resampling framework
spde_Q_phi

Calculate the SPDE covariance
plot.act_BGLM

S3 method: use view_xifti to plot a "act_BGLM" object
nuisance_Param_BayesGLM

nuisance
summary.prev_BGLM

Summarize a "prev_BGLM" object
plot.prev_BGLM

S3 method: use view_xifti to plot a "prev_BGLM" object
retro_mask_act

Retroactively mask activations
session_names_Param

session_names
seed_Param

seed
vol2spde

Construct a triangular mesh from a 3D volumetric mask
summary.prev_fit_bglm

Summarize a "prev_fit_bglm" object
retro_mask_fit_bglm

Retroactively mask locations from fit_bglm result.
BayesGLM_format_design

Format design
BayesGLM_format_nuisance

Format nuisance
BOLD_Param_BayesGLM

BOLD
EM_Param

EM
AICc

Corrected AIC
ELL

Expected log-likelihood function