templateICA: Template ICA

View source: R/templateICA.R

templateICAR Documentation

Template ICA

Description

Perform template independent component analysis (ICA) using variational Bayes (VB) or expectation-maximization (EM).

Usage

templateICA(
  BOLD,
  template,
  tvar_method = c("non-negative", "unbiased"),
  scale = c("template", "global", "local", "none"),
  scale_sm_surfL = NULL,
  scale_sm_surfR = NULL,
  scale_sm_FWHM = "template",
  nuisance = NULL,
  scrub = NULL,
  TR = NULL,
  hpf = "template",
  GSR = "template",
  Q2 = "template",
  Q2_max = "template",
  brainstructures = "template",
  mask = NULL,
  time_inds = NULL,
  varTol = "template",
  spatial_model = NULL,
  resamp_res = NULL,
  rm_mwall = TRUE,
  reduce_dim = FALSE,
  method_FC = c("VB1", "VB2", "none"),
  maxiter = 100,
  miniter = 3,
  epsilon = 0.001,
  kappa_init = 0.2,
  usePar = TRUE,
  PW = FALSE,
  verbose = TRUE
)

Arguments

BOLD

Vector of subject-level fMRI data in one of the following formats: CIFTI file paths, "xifti" objects, NIFTI file paths, "nifti" objects, or V \times T numeric matrices, where V is the number of data locations and T is the number of timepoints.

If multiple BOLD data are provided, they will be independently centered, scaled, detrended (if applicable), and denoised (if applicable). Then they will be concatenated together followed by computing the initial dual regression estimate.

template

Template estimates in a format compatible with BOLD, from estimate_template.

tvar_method

Which calculation of the template variance to use: "non-negative" (default) or "unbiased". The unbiased template variance is based on the assumed mixed effects/ANOVA model, whereas the non-negative template variance adds to it to account for greater potential between-subjects variation. (The template mean is the same for either choice of tvar_method.)

scale

"global", "local", or "none". Global scaling will divide the entire data matrix by the mean image standard deviation (mean(sqrt(rowVars(BOLD)))). Local scaling will divide each data location's time series by its estimated standard deviation. Default: "template", to use the same option used for estimation of the template.

scale_sm_surfL, scale_sm_surfR, scale_sm_FWHM

Only applies if scale=="local" and BOLD represents CIFTI-format data. To smooth the standard deviation estimates used for local scaling, provide the surface geometries along which to smooth as GIFTI geometry files or "surf" objects, as well as the smoothing FWHM (default: "template" to use the same option used for estimation of the template).

If scale_sm_FWHM==0, no smoothing of the local standard deviation estimates will be performed.

If scale_sm_FWHM>0 but scale_sm_surfL and scale_sm_surfR are not provided, the default inflated surfaces from the HCP will be used.

To create a "surf" object from data, see make_surf. The surfaces must be in the same resolution as the BOLD data.

nuisance

(Optional) Signals to regress from the data, given as a numeric matrix with the same number of rows as there are volumes in the BOLD data. If multiple BOLD sessions are provided, this argument can be a list to use different nuisance regressors for different sessions. Nuisance regression is performed as a first step, before centering, scaling, and denoising. An intercept column will automatically be added to nuisance. If NULL, no extra nuisance signals will be regressed from the data, but a nuisance regression will still be used if warranted by scrub or hpf.

scrub

(Optional) A numeric vector of integers indicating the indices of volumes to scrub from the BOLD data. (List the volumes to remove, not the ones to keep.) If multiple BOLD sessions are provided, this argument can be a list to remove different volumes for different sessions. Scrubbing is performed within nuisance regression by adding a spike regressor to the nuisance design matrix for each volume to scrub. If NULL, do not scrub.

TR, hpf

These arguments control detrending. TR is the temporal resolution of the data, i.e. the time between volumes, in seconds; hpf is the frequency of the high-pass filter, in Hertz. Detrending is performed via nuisance regression of DCT bases. Default: "template" to use the values from the template. Be sure to set the correct TR if it's different for the new data compared to the data used in estimate_template.

Note that if multiple BOLD sessions are provided, their TR and hpf must be the same; both arguments accept only one value.

GSR

Center BOLD across columns (each image)? This is equivalent to performing global signal regression. Default: "template", to use the same option used for estimation of the template.

Q2, Q2_max

Denoise the BOLD data? Denoising is based on modeling and removing nuisance ICs. It may result in a cleaner estimate for smaller datasets, but it may be unnecessary (and time-consuming) for larger datasets.

Set Q2 to control denoising: use a positive integer to specify the number of nuisance ICs, NULL to have the number of nuisance ICs estimated by PESEL, or zero to skip denoising.

If is.null(Q2), use Q2_max to specify the maximum number of nuisance ICs that should be estimated by PESEL. Q2_max must be less than T * .75 - Q where T is the number of timepoints in BOLD and Q is the number of group ICs. If NULL, Q2_max will be set to T * .50 - Q, rounded.

The defaults for both arguments is "template", to use the same option used for estimation of the template.

brainstructures

Only applies if the entries of BOLD are CIFTI file paths. This is a character vector indicating which brain structure(s) to obtain: "left" (left cortical surface), "right" (right cortical surface) and/or "subcortical" (subcortical and cerebellar gray matter). Can also be "all" (obtain all three brain structures). Default: "template" to use the same brainstructures present in the template).

mask

Required if and only if the entries of BOLD are NIFTI file paths or "nifti" objects. This is a brain map formatted as a binary array of the same spatial dimensions as the fMRI data, with TRUE corresponding to in-mask voxels.

time_inds

Subset of fMRI BOLD volumes to include in analysis, as a vector of numeric integers. If NULL (default), use all volumes. Subsetting is performed before any centering, scaling, detrending, and denoising. If multiple BOLD are provided, time_inds can be a list of the same length, with each element being a vector of numeric integers indicating the timepoints to include for each BOLD.

varTol

Tolerance for variance of each data location. For each scan, locations which do not meet this threshold are masked out of the analysis. Default: "template" to use the same brainstructures present in the template). Variance is calculated on the original data, before any normalization. Set to 0 to avoid removing locations due to low variance.

spatial_model

Should spatial modeling be performed? If NULL, assume spatial independence. Otherwise, provide meshes specifying the spatial priors assumed on each independent component. Each should represent a brain structure, between which spatial independence can be assumed.

If BOLD represents CIFTI-format data, spatial_model should give the left and right cortex surface geometries (whichever one(s) are being used) as "surf" objects or GIFTI surface geometry file paths. Spatial modeling is not yet available for the subcortex. This argument can also be TRUE, in which case spatial modeling will be performed with the surfaces included in the first entry of BOLD if it is a "xifti" object, or if those are not present available, the default inflated surfaces from ciftiTools.

If BOLD represents NIFTI-format data, spatial modeling is not yet available.

If BOLD is a numeric matrix, spatial_model should be a list of meshes (see make_mesh).

resamp_res

Only applies if BOLD represents CIFTI-format data. The target resolution for resampling (number of cortical surface vertices per hemisphere). For spatial modelling, a value less than 10000 is recommended for computational feasibility. If NULL (default), do not perform resampling.

rm_mwall

Only applies if BOLD represents CIFTI-format data. Should medial wall (missing data) locations be removed from the mesh? If TRUE, faster computation but less accurate estimates at the boundary of wall.

reduce_dim

Reduce the temporal dimension of the data using PCA? Default: TRUE. Skipping dimension reduction will slow the model estimation, but may result in more accurate results. Ignored for FC template ICA

method_FC

Variational Bayes (VB) method for FC template ICA model: "VB1" (default) uses a conjugate Inverse-Wishart prior for the cor(A); "VB2" draws samples from p(cor(A)) to emulate the population distribution using a combination of Cholesky, SVD, and random pivoting. "none" Uses standard template ICA without FC prior

maxiter

Maximum number of EM or VB iterations. Default: 100.

miniter

Minimum number of EM or VB iterations. Default: 3.

epsilon

Smallest proportion change between iterations. Default: .001.

kappa_init

Starting value for kappa. Default: 0.2.

usePar

Parallelize the computation? Default: TRUE. Can be the number of cores to use or TRUE, which will use the number available minus two.

PW

Prewhiten to account for residual autocorrelation? Default: FALSE. Only affects FC template ICA models.

verbose

If TRUE, display progress of algorithm

Value

A (spatial) template ICA object, which is a list containing: subjICmean, the V \times L estimated independent components S; subjICse, the standard errors of S; the mask of locations without template values due to too many low variance or missing values; the nuisance design matrix or matrices if applicable; and the function params such as the type of scaling and detrending performed.

If BOLD represented CIFTI or NIFTI data, subjICmean and subjICse will be formatted as "xifti" or "nifti" objects, respectively.

Examples

## Not run: 
 tm <- estimate_template(cii1_fnames, cii2_fnames, gICA_fname)
 templateICA(newcii_fname, tm, spatial_model=TRUE, resamp_res=2000)

## End(Not run)

templateICAr documentation built on April 3, 2025, 7:41 p.m.