Type: | Package |
Title: | Estimate Brain Networks and Connectivity with ICA and Empirical Priors |
Version: | 0.10.0 |
Maintainer: | Amanda Mejia <mandy.mejia@gmail.com> |
Description: | Implements the template ICA (independent components analysis) model proposed in Mejia et al. (2020) <doi:10.1080/01621459.2019.1679638> and the spatial template ICA model proposed in proposed in Mejia et al. (2022) <doi:10.1080/10618600.2022.2104289>. Both models estimate subject-level brain as deviations from known population-level networks, which are estimated using standard ICA algorithms. Both models employ an expectation-maximization algorithm for estimation of the latent brain networks and unknown model parameters. Includes direct support for 'CIFTI', 'GIFTI', and 'NIFTI' neuroimaging file formats. |
Depends: | R (≥ 3.6.0) |
License: | GPL-3 |
Additional_repositories: | https://inla.r-inla-download.org/R/testing |
Encoding: | UTF-8 |
Imports: | abind, fMRItools (≥ 0.5.3), fMRIscrub (≥ 0.14.5), foreach, ica, Matrix, matrixStats, methods, pesel, SQUAREM, stats, utils |
Suggests: | ciftiTools (≥ 0.13.2), excursions, RNifti, oro.nifti, gifti, covr, parallel, doParallel, knitr, rmarkdown, INLA, testthat (≥ 3.0.0) |
RoxygenNote: | 7.3.2 |
URL: | https://github.com/mandymejia/templateICAr |
BugReports: | https://github.com/mandymejia/templateICAr/issues |
NeedsCompilation: | no |
Packaged: | 2025-05-19 20:29:43 UTC; ddpham |
Author: | Amanda Mejia [aut, cre],
Damon Pham |
Repository: | CRAN |
Date/Publication: | 2025-05-19 21:00:02 UTC |
Cholesky-based FC sampling
Description
Cholesky-based FC sampling
Usage
Chol_samp_fun(Chol_vals, p, M, chol_diag, chol_offdiag, Chol_mat_blank)
Arguments
Chol_vals |
Matrix of Cholesky factorizations (upper triangular values) for all template sessions (nN*nM x nChol) |
p |
Pivot/reordering applied to FC matrices prior to Cholesky factorization |
M |
Number of samples to draw |
chol_diag |
Indices of diagonal upper triangular elements |
chol_offdiag |
Indices of off-diagonal upper triangular elements |
Chol_mat_blank |
A nLxnL matrix indexing the upper triangular elements |
EM Algorithms for Template ICA Models
Description
EM Algorithms for Template ICA Models
Usage
EM_templateICA.spatial(
template_mean,
template_var,
meshes,
BOLD,
theta0,
C_diag,
H,
Hinv,
maxiter = 100,
usePar = FALSE,
epsilon = 0.001,
reduce_dim = TRUE,
verbose = FALSE
)
EM_templateICA.independent(
template_mean,
template_var,
BOLD,
theta0,
C_diag,
H,
Hinv,
maxiter = 100,
epsilon = 0.001,
reduce_dim = FALSE,
usePar = FALSE,
verbose
)
Arguments
template_mean |
( |
template_var |
( |
meshes |
|
BOLD |
( |
theta0 |
(list) initial guess at parameter values: A ( |
C_diag |
( |
H , Hinv |
For dimension reduction
of the spatial template ICA model, which assumes that all IC's have the
same smoothness parameter, |
maxiter |
Maximum number of EM iterations. Default: 100. |
usePar |
Parallelize the computation? Default: |
epsilon |
Smallest proportion change between iterations. Default: 0.001. |
reduce_dim |
Reduce the temporal dimension of the data using PCA?
Default: |
verbose |
If |
Details
EM_templateICA.spatial
implements the expectation-maximization
(EM) algorithm described in Mejia et al. (2019+) for estimating the
subject-level ICs and unknown parameters in the template ICA model with
spatial priors on subject effects.
In both models, if original fMRI timeseries has covariance
\sigma^2 I_T
, the prewhitened timeseries achieved by premultiplying
by (QxT
) matrix H
from PCA has diagonal covariance
\sigma^2HH'
, so C_diag is diag(HH')
.
Value
A list: theta (list of final parameter estimates), subICmean
(estimates of subject-level ICs), subICvar (variance of subject-level ICs,
for non-spatial model) or subjICcov (covariance matrix of subject-level ICs,
for spatial model – note that only diagonal and values for neighbors are
computed), and success (flag indicating convergence (TRUE
) or not
(FALSE
))
GSR
Description
GSR
Arguments
GSR |
Center BOLD across columns (each image)? This
is equivalent to performing global signal regression. Default:
|
Check for INLA
Description
Check for INLA
Usage
INLA_check()
Value
NULL
, invisibly
Compute theoretical Inverse-Wishart variance of covariance matrix elements
Description
Compute theoretical Inverse-Wishart variance of covariance matrix elements
Usage
IW_var(nu, p, xbar_ij, xbar_ii, xbar_jj)
Arguments
nu |
Inverse Wishart degrees of freedom parameter |
p |
Matrix dimension for IW distribution |
xbar_ij |
Empirical mean of covariance matrices at element (i,j) |
xbar_ii |
Empirical mean of covariance matrices at the ith diagonal element |
xbar_jj |
Empirical mean of covariance matrices at the jth diagonal element |
Value
Theoretical IW variance for covariance element (i,j)
Compute theoretical Inverse-Wishart variance of correlation matrix elements
Description
Compute theoretical Inverse-Wishart variance of correlation matrix elements
Usage
IW_var_cor(nu, p, xbar_ij)
Arguments
nu |
Inverse Wishart degrees of freedom parameter |
p |
Matrix dimension for IW distribution |
xbar_ij |
Empirical mean of covariance matrices at element (i,j) |
Value
Theoretical IW variance for correlation element (i,j)
Compute part of kappa log-likelihood
Description
Compute part of log-likelihood involving kappa (or kappa_q) for numerical optimization
Usage
LL2_kappa(
kappa,
Amat,
Fmat,
Gmat,
GFinvG,
OplusW,
u,
v,
C1 = 1/(4 * pi),
Q = NULL
)
Arguments
kappa |
Value of kappa for which to compute log-likelihood |
Amat |
Mesh projection matrix |
Fmat |
Matrix used in computation of SPDE precision |
Gmat |
Matrix used in computation of SPDE precision |
GFinvG |
Matrix used in computation of SPDE precision |
OplusW |
Sparse matrix containing estimated values of RHS of trace in part 2 of log-likelihood. In common smoothness model, represents the sum over q=1,...,Q. |
u |
Vector needed for part 3 of log-likelihood |
v |
Vector needed for part 3 of log-likelihood |
C1 |
For the unit variance case, |
Q |
Equal to the number of ICs for the common smoothness model, or NULL for the IC-specific smoothness model |
Details
This is the function to be maximized in order to determine the MLE for \kappa
or the \kappa_q
's in the M-step of the EM algorithm in spatial
template ICA. In the model where \kappa_q
can be different for each IC q
, the optimization function factorizes over the \kappa_q
's. This function computes
the value of the part of the optimization function pertaining to one of the \kappa_q
's.
Value
Value of log-likelihood at logkappa
Log-likelihood SQUAREM
Description
Helper function for SQUAREM for extracting log likelihood
Usage
LL_SQUAREM(theta_vec, ...)
Arguments
theta_vec |
Vector of current parameter values |
Value
Negative log-likelihood given current values of parameters
Check Q2_max
Description
Check Q2_max
and set it if NULL
.
Usage
Q2_max_check(Q2_max, nQ, nT)
Arguments
Q2_max , nQ , nT |
The args |
Value
Q2_max
, clamped to acceptable range of values.
TR
Description
TR
Arguments
TR |
The temporal resolution of the data, i.e. the time between volumes,
in seconds. |
Transform upper-triangular elements to matrix form
Description
Transform upper-triangular elements to matrix form
Usage
UT2mat(x, diag = TRUE)
Arguments
x |
Vector of upper triangular values |
diag |
Are diagonal values included in x? Default: |
Update theta SQUAREM
Description
Helper function for SQUAREM for estimating parameters
Usage
UpdateThetaSQUAREM_templateICA(
theta_vec,
template_mean,
template_var,
meshes,
BOLD,
C_diag,
H,
Hinv,
s0_vec,
D,
Dinv_s0,
update_nu0sq,
verbose
)
Arguments
theta_vec |
Vector of initial parameter values |
template_mean |
Passed to UpdateTheta_templateICA function |
template_var |
Passed to UpdateTheta_templateICA function |
meshes |
Passed to UpdateTheta_templateICA function |
BOLD |
Passed to UpdateTheta_templateICA function |
C_diag |
Passed to UpdateTheta_templateICA function |
s0_vec |
Passed to UpdateTheta_templateICA function |
D |
Passed to UpdateTheta_templateICA function |
Dinv_s0 |
Passed to UpdateTheta_templateICA function |
update_nu0sq |
For non-spatial model: updating |
verbose |
Passed to UpdateTheta_templateICA function |
Value
Vector of updated parameter values
Parameter Estimates in EM Algorithm for Template ICA Model
Description
Parameter Estimates in EM Algorithm for Template ICA Model
Usage
UpdateTheta_templateICA.spatial(
template_mean,
template_var,
meshes,
BOLD,
theta,
C_diag,
H,
Hinv,
s0_vec,
D,
Dinv_s0,
verbose = FALSE,
return_MAP = FALSE,
update = c("all", "kappa", "A")
)
UpdateTheta_templateICA.independent(
template_mean,
template_var,
BOLD,
theta,
C_diag,
H,
Hinv,
update_nu0sq = TRUE,
return_MAP = FALSE,
verbose = TRUE
)
Arguments
template_mean |
( |
template_var |
( |
meshes |
|
BOLD |
( |
theta |
(list) current parameter estimates |
C_diag |
|
H , Hinv |
For dimension reduction |
s0_vec |
Vectorized template means |
D |
Sparse diagonal matrix of template standard deviations |
Dinv_s0 |
The inverse of D times s0_vec |
verbose |
If |
return_MAP |
If |
update |
Which parameters to update. Either |
update_nu0sq |
For non-spatial model: updating |
Value
An updated list of parameter estimates, theta, OR if
return_MAP=TRUE
, the posterior mean and precision of the latent fields
VB_FCtemplateICA
Description
VB Algorithm for FC Template ICA Model
Usage
VB_FCtemplateICA(
template_mean,
template_var,
template_FC,
method_FC = c("VB1", "VB2"),
nsamp_u = 10000,
CI_FC = 0.95,
return_FC_samp = FALSE,
prior_params = c(0.001, 0.001),
BOLD,
TR = NULL,
A0,
S0,
S0_var,
maxiter = 100,
miniter = 3,
epsilon = 0.001,
usePar = TRUE,
PW = FALSE,
verbose = FALSE
)
Arguments
template_mean |
( |
template_var |
( |
template_FC |
(list) Parameters of functional connectivity template. |
method_FC |
Variational Bayes (VB) method for FC template ICA model:
|
nsamp_u |
For VB1, the number of samples to generate from u ~ Gamma, where
A is Gaussian conditional on u. Default: |
CI_FC |
Level of posterior credible interval to construct for each FC element.
Default: |
return_FC_samp |
Should the FC samples ( |
prior_params |
Alpha and beta parameters of IG prior on |
BOLD |
( |
A0 , S0 , S0_var |
Initial guesses at latent variables: |
maxiter |
Maximum number of VB iterations. Default: |
miniter |
Minimum number of VB iterations. Default: |
epsilon |
Smallest proportion change in parameter estimates between iterations.
Default: |
usePar |
Parallelize the computation? Default: |
PW |
Prewhiten to account for residual autocorrelation? |
verbose |
If |
Value
A list of computed values, including the final parameter estimates.
Activations of (spatial) template ICA
Description
Identify areas of activation in each independent component map from the result of (spatial) template ICA.
Usage
activations(
tICA,
u = NULL,
z = NULL,
alpha = 0.01,
type = c(">", "abs >", "<", "!="),
method_p = "BH",
verbose = FALSE,
which.ICs = NULL,
deviation = FALSE
)
Arguments
tICA |
Fitted (spatial) template ICA object from |
u , z |
Set a threshold value for activation? A threshold value can be
specified directly with |
alpha |
Significance level for hypothesis testing. Default: |
type |
Type of region: |
method_p |
If the input is a |
verbose |
If |
which.ICs |
Indices of ICs for which to identify activations. If
|
deviation |
If |
Value
A list containing activation maps for each IC, the joint and marginal PPMs for each IC, and the parameters used for computing activation. If the input represented CIFTI- or NIFTI-format data, then the activations maps will be formatted accordingly.
Use summary
to obtain information about the activations results.
For CIFTI-format activations, use plot
to visualize the activation
maps.
Examples
## Not run:
activations(tICA_result, alpha=.05, deviation=TRUE)
## End(Not run)
Combine additive terms in string
Description
Combine two terms with "+" or "-" in a string
Usage
add_str(a, b)
Arguments
a , b |
The two terms. Each is a length-one character vector. |
Value
The result as a length-one character vector.
Block diagonal matrix
Description
Code for function provided in examples of bdiag function from Matrix package
Usage
bdiag_m(lmat)
Arguments
lmat |
List of matrices |
Details
Construct block diagonal matrix of many small blocks
Value
A sparse matrix obtained by combining the arguments into a block diagonal matrix
Bdiag m2
Description
Bdiag m2
Usage
bdiag_m2(mat, N)
Arguments
mat |
a k x k 'matrix' |
N |
how many times to repeat |
Value
a sparse (Nk x Nk) matrix of class "dgCMatrix"
.
Check for required parallel packages
Description
Check that required packages for parallel computation are available. If not, stop execution with a helpful error message.
Usage
check_parallel_packages()
Value
NULL
, invisibly
Check required packages for the data format
Description
Check required packages for the data format
Usage
check_req_ifti_pkg(FORMAT)
Arguments
FORMAT |
The data FORMAT |
Value
NULL
, invisibly
Compute LL for EM Template ICA
Description
Compute the expected log posterior for EM Standard Template ICA
Usage
compute_LL_std(theta, template_mean, template_var, C_diag, BOLD, verbose)
Arguments
theta |
The current parameter estimates |
template_mean , template_var |
The template |
C_diag |
The C matrix |
BOLD |
( |
verbose |
Print LL components? |
Value
The expected log posterior at the current values
Compute SPDE and prior precision matrices for S
Description
Compute SPDE matrices (F, G and GFinvG) and prior precision matrix for S
Usage
compute_R_inv(meshes, kappa, C1 = 1/(4 * pi), rm_extra = FALSE)
Arguments
meshes |
|
kappa |
Current estimates of SPDE parameter kappa for each latent field |
C1 |
Constant, equal to |
rm_extra |
If |
Value
A list containing R inverse and SPDE matrices
Compute posterior mean and precision of s
Description
Compute posterior mean and precision matrix of s
Usage
compute_mu_s(y_vec, D, Dinv_s0, R_inv, theta, P, C_diag)
Arguments
y_vec |
Vectorized, dimension-reduced fMRI data, grouped by locations. A vector of length |
D |
Sparse diagonal matrix of template standard deviations |
Dinv_s0 |
The inverse of D times s0_vec |
R_inv |
Estimate of inverse spatial correlation matrix (sparse) |
theta |
List of current parameter estimates |
P |
Permutation matrix for regrouping by locations (instead of by ICs.) |
C_diag |
Diagonals of residual covariance of the first level model. A vector of length |
Value
A list containing the posterior mean \mu
(mu) and precision
\Omega
(Omega) of s=(s1,...,sQ), along with the supporting vector m,
where \mu = \Omega^{-1}m
.
PCA-based Dimension Reduction and Prewhitening
Description
Performs dimension reduction and prewhitening based on probabilistic PCA using SVD. If dimensionality is not specified, it is estimated using the method described in Minka (2008).
Usage
dim_reduce(X, Q = NULL, Q_max = 100)
Arguments
X |
A numeric matrix, with each column being a centered timeseries.
For fMRI data, |
Q |
Number of latent dimensions to estimate. If |
Q_max |
Maximal number of principal components for automatic
dimensionality selection with PESEL. Default: |
Value
A list containing the dimension-reduced data (data_reduced
, a
V \times Q
matrix), prewhitening/dimension reduction matrix (H
,
a QxT
matrix) and its (pseudo-)inverse (Hinv
, a TxQ
matrix), the noise variance (sigma_sq
), the correlation matrix of the
dimension-reduced data (C_diag
, a QxQ
matrix), and the
dimensionality (Q
).
Examples
nT <- 30
nV <- 400
nQ <- 7
X <- matrix(rnorm(nV*nQ), nrow=nV) %*% diag(seq(nQ, 1)) %*% matrix(rnorm(nQ*nT), nrow=nQ)
dim_reduce(X, Q=nQ)
Dual Regression wrapper
Description
Wrapper to dual_reg
used by estimate_template
. The format of BOLD
(and BOLD2
) must be provided, and GICA
must be vectorized if applicable.
Usage
dual_reg2(
BOLD,
BOLD2 = NULL,
format = c("CIFTI", "xifti", "GIFTI", "gifti", "NIFTI", "nifti", "RDS", "data"),
GICA,
GICA_parc_table = NULL,
mask = NULL,
keepA = FALSE,
scale = c("local", "global", "none"),
scale_sm_surfL = NULL,
scale_sm_surfR = NULL,
scale_sm_FWHM = 2,
TR = NULL,
hpf = 0.01,
GSR = FALSE,
Q2 = 0,
Q2_max = NULL,
NA_limit = 0.1,
brainstructures = "all",
resamp_res = NULL,
varTol = 1e-06,
maskTol = 0.1,
verbose = TRUE
)
Arguments
BOLD , BOLD2 |
Subject-level fMRI data in one of the following formats:
a CIFTI file path, a If If |
format |
Expected format of |
GICA |
Group ICA maps as a (vectorized) numeric matrix
( |
GICA_parc_table |
Is the GICA actually a parcellation? If so, provide
the parcellation table here. Default: |
mask |
Required if and only if the entries of |
keepA |
Keep the resulting A matrices, or only return the S matrices (default)? |
scale |
|
scale_sm_surfL , scale_sm_surfR , scale_sm_FWHM |
Only applies if
If If To create a |
TR |
The temporal resolution of the data, i.e. the time between volumes,
in seconds. |
hpf |
The frequency at which to apply a highpass filter to the data
during pre-processing, in Hertz. Default: The highpass filter serves to detrend the data, since low-frequency variance is associated with noise. Highpass filtering is accomplished by nuisance regression of discrete cosine transform (DCT) bases. Note the |
GSR |
Center BOLD across columns (each image)? This
is equivalent to performing global signal regression. Default:
|
Q2 , Q2_max |
Obtain dual regression estimates after denoising? 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 If |
brainstructures |
Only applies if the entries of |
resamp_res |
Only applies if the entries of |
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: |
maskTol |
Tolerance for number of locations masked out due to low
variance or missing values. If more than this many locations are masked out,
this subject is skipped without calculating dual regression. If |
verbose |
Display progress updates? Default: |
Value
The dual regression S matrices, or both the S
and A matrices if keepA
, or NULL
if dual
regression was skipped due to too many masked data locations.
Estimation of effective sample size
Description
Estimation of effective sample size
Usage
estimate.ESS(mesh, Y, ind = NULL, trace = FALSE)
Arguments
mesh |
INLA mesh |
Y |
data |
ind |
index of the data locations in the mesh |
trace |
If |
Details
The functions computes the effective sample size as trace(Q^{-1})/trace(Q*Q)
as in Bretherton et al. (1999), Journal of Climate.
Value
Estimate of the effective sample size
Universally estimate IW dof parameter nu based on method of moments, so that no empirical variance is under-estimated
Description
Universally estimate IW dof parameter nu based on method of moments, so that no empirical variance is under-estimated
Usage
estimate_nu(var_FC, mean_FC)
Arguments
var_FC |
Empirical between-subject variance of covariance matrices (QxQ) |
mean_FC |
Empirical mean of covariance matrices (QxQ) |
Value
estimate for nu
Estimate IW dof parameter nu based on method of moments
Description
Estimate IW dof parameter nu based on method of moments
Usage
estimate_nu_matrix(var_FC, mean_FC)
Arguments
var_FC |
Empirical between-subject variance of covariance matrices (QxQ) |
mean_FC |
Empirical mean of covariance matrices (QxQ) |
Value
QxQ matrix of estimates for nu
Estimate template
Description
Estimate template for Template ICA based on fMRI data
Usage
estimate_template(
BOLD,
BOLD2 = NULL,
GICA,
mask = NULL,
inds = NULL,
scale = c("local", "global", "none"),
scale_sm_surfL = NULL,
scale_sm_surfR = NULL,
scale_sm_FWHM = 2,
TR = NULL,
hpf = 0.01,
GSR = FALSE,
Q2 = 0,
Q2_max = NULL,
covariates = NULL,
brainstructures = "all",
resamp_res = NULL,
keep_S = FALSE,
keep_FC = FALSE,
FC = TRUE,
FC_nPivots = 100,
FC_nSamp = 50000,
varTol = 1e-06,
maskTol = 0.1,
missingTol = 0.1,
usePar = FALSE,
wb_path = NULL,
verbose = TRUE
)
estimate_template.cifti(
BOLD,
BOLD2 = NULL,
GICA,
inds = NULL,
scale = c("local", "global", "none"),
scale_sm_surfL = NULL,
scale_sm_surfR = NULL,
scale_sm_FWHM = 2,
TR = NULL,
hpf = 0.01,
GSR = FALSE,
Q2 = 0,
Q2_max = NULL,
brainstructures = "all",
resamp_res = resamp_res,
keep_S = FALSE,
keep_FC = FALSE,
FC = FALSE,
varTol = 1e-06,
maskTol = 0.1,
missingTol = 0.1,
usePar = FALSE,
wb_path = NULL,
verbose = TRUE
)
estimate_template.gifti(
BOLD,
BOLD2 = NULL,
GICA,
inds = NULL,
scale = c("local", "global", "none"),
scale_sm_surfL = NULL,
scale_sm_surfR = NULL,
scale_sm_FWHM = 2,
TR = NULL,
hpf = 0.01,
GSR = FALSE,
Q2 = 0,
Q2_max = NULL,
brainstructures = "all",
keep_S = FALSE,
keep_FC = FALSE,
FC = FALSE,
varTol = 1e-06,
maskTol = 0.1,
missingTol = 0.1,
usePar = FALSE,
wb_path = NULL,
verbose = TRUE
)
estimate_template.nifti(
BOLD,
BOLD2 = NULL,
GICA,
inds = NULL,
scale = c("local", "global", "none"),
TR = NULL,
hpf = 0.01,
GSR = FALSE,
Q2 = 0,
Q2_max = NULL,
mask = NULL,
keep_S = FALSE,
keep_FC = FALSE,
FC = FALSE,
varTol = 1e-06,
maskTol = 0.1,
missingTol = 0.1,
usePar = FALSE,
wb_path = NULL,
verbose = TRUE
)
Arguments
BOLD , BOLD2 |
Vector of subject-level fMRI data in one of the following
formats: CIFTI file paths, If |
GICA |
Group ICA maps in a format compatible with New: can also be a parcellation in CIFTI format (other formats to be implemented in the future). The parcellation should have the same locations and one column, with integer values indicating the parcel to which each location belongs to. Each parcel is modeled as a brain map; instead of the first step of dual regression, the medial timecourse of each parcel is used. |
mask |
Required if |
inds |
Numeric indices of the group ICs to include in the template. If
If |
scale |
|
scale_sm_surfL , scale_sm_surfR , scale_sm_FWHM |
Only applies if
If If To create a |
TR |
The temporal resolution of the data, i.e. the time between volumes,
in seconds. |
hpf |
The frequency at which to apply a highpass filter to the data
during pre-processing, in Hertz. Default: The highpass filter serves to detrend the data, since low-frequency variance is associated with noise. Highpass filtering is accomplished by nuisance regression of discrete cosine transform (DCT) bases. Note the |
GSR |
Center BOLD across columns (each image)? This
is equivalent to performing global signal regression. Default:
|
Q2 , Q2_max |
Obtain dual regression estimates after denoising? 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 If |
covariates |
Subjects by variables numeric matrix of covariates to take
into account for model estimation. Column names should give the name of each
variable. Default: |
brainstructures |
Only applies if the entries of |
resamp_res |
Only applies if the entries of |
keep_S |
Keep the DR estimates of S? If |
keep_FC |
Keep the DR estimates of the FC cor(A)? If |
FC |
Include the functional connectivity template? Default: |
FC_nPivots |
Number of pivots to use in Cholesky-based FC template estimation. Set to zero to skip Cholesky-based FC template estimation. Default: 100. |
FC_nSamp |
Number of FC matrix samples to generate across all pivots. This should be a multiple of FC_nPivots. |
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: |
maskTol |
For computing the dual regression results for each subject:
tolerance for number of locations masked out due to low
variance or missing values. If more than this many locations are masked out,
a subject is skipped without calculating dual regression. If |
missingTol |
For computing the variance decomposition across all subjects:
tolerance for number of subjects masked out due to low variance or missing
values at a given location. If more than this many subjects are masked out,
the location's value will be |
usePar , wb_path |
Parallelize the DR computations over subjects? Default:
|
verbose |
Display progress updates? Default: |
Details
All fMRI data (entries in BOLD
and BOLD2
, and GICA
) must
be in the same spatial resolution.
Value
A list: the template
and var_decomp
with entries in
matrix format; the mask
of locations without template values due to
too many low variance or missing values; the function params
such as
the type of scaling and detrending performed; the dat_struct
which can be
used to convert template
and var_decomp
to "xifti"
or
"nifti"
objects if the BOLD
format was CIFTI or NIFTI data;
and DR results if isTRUE(keep_S)
and/or isTRUE(keep_FC)
.
Use summary
to print a description of the template results, and
for CIFTI-format data use plot
to plot the template mean and variance
estimates. Use export_template
to save the templates to
individual RDS, CIFTI, or NIFTI files (depending on the BOLD
format).
Examples
nT <- 21
nV <- 140
nQ <- 6
mU <- matrix(rnorm(nV*nQ), nrow=nV)
mS <- mU %*% diag(seq(nQ, 1)) %*% matrix(rnorm(nQ*nT), nrow=nQ)
BOLD <- list(B1=mS, B2=mS, B3=mS)
BOLD <- lapply(BOLD, function(x){x + rnorm(nV*nT, sd=.05)})
GICA <- mU
estimate_template(BOLD=BOLD, GICA=mU, FC_nSamp=2000)
## Not run:
estimate_template(
run1_cifti_fnames, run2_cifti_fnames,
gICA_cifti_fname, brainstructures="all",
scale="global", TR=0.71, Q2=NULL, varTol=10
)
## End(Not run)
Estimate FC template
Description
Estimate FC template
Usage
estimate_template_FC(FC0, nu_adjust = 1)
Arguments
FC0 |
The FC estimates from |
nu_adjust |
Factor by which to adjust estimate of nu. Values < 1 will inflate the template variance to avoid an over-informative prior on FC. |
Estimate template from DR
Description
Estimate variance decomposition and templates from DR estimates.
Usage
estimate_template_from_DR(DR, LV = NULL)
Arguments
DR |
the test/retest dual regression estimates, as an array with
dimensions ( |
LV |
A length-two integer vector giving the dimensions |
Value
List of two elements: the templates and the variance decomposition.
There are two version of the variance template: varUB
gives the
unbiased variance estimate, and varNN
gives the upwardly-biased
non-negative variance estimate. Values in varUB
will need to be
clamped above zero before using in templateICA
.
Estimate template from DR estimates (when there are two measurements)
Description
Legacy version of estimate_template_from_DR
Usage
estimate_template_from_DR_two(DR1, DR2)
Arguments
DR1 , DR2 |
the test and retest dual regression estimates ( |
Value
List of two elements: the mean and variance templates
Export template
Description
Export the templates (mean and variance) as separate files for
visualization or processing outside of templateICAr
.
Usage
export_template(
x,
out_fname = NULL,
var_method = c("non-negative", "unbiased")
)
Arguments
x |
The result of |
out_fname |
Use |
var_method |
|
Value
If is.null(out_fname)
, the templates in data matrix,
"xifti"
, or "nifti"
format, to match the format of the
original BOLD data. Otherwise, the paths to the new files specified by
out_fname
. If template includes functional connectivity components,
the FC template and its mean and variance will be included.
Examples
## Not run:
tm <- estimate_template(cii1_fnames, cii2_fnames, gICA_fname)
export_template(tm, out_fname="my_template", var_method="unbiased")
## End(Not run)
Format activation name
Description
Format the name of an activation, given parameters of the statistical test.
Usage
format_activation_name(u, z, type, deviation, collapse = FALSE)
Arguments
u , z , type , deviation |
See |
collapse |
If multiple |
Compute inverse covariance matrix for AR process (up to a constant scaling factor)
Description
Compute inverse covariance matrix for AR process (up to a constant scaling factor)
Usage
getInvCovAR(ar, ntime)
Arguments
ar |
vector of p AR parameters |
ntime |
number of time points in timeseries |
Value
inverse covariance matrix for AR process (up to a constant scaling factor)
Get FORMAT from format
Description
Get FORMAT from format
Usage
get_FORMAT(format)
Arguments
format |
the file format |
Value
The file FORMAT
Perform group ICA based on CIFTI data
Description
Perform group ICA based on CIFTI data
Usage
groupICA.cifti(
cifti_fnames,
subjects = NULL,
brainstructures = "all",
num_PCs = 100,
num_ICs,
max_rows_GPCA = 10000,
GSR = FALSE,
scale = c("local", "global", "none"),
scale_sm_FWHM = 2,
TR = NULL,
hpf = 0.01,
verbose = TRUE,
out_fname = NULL,
surfL = NULL,
surfR = NULL,
smooth = TRUE,
smooth_surf_FWHM = 5,
smooth_vol_FWHM = 5,
smooth_zeroes_as_NA = FALSE,
smooth_subcortical_merged = FALSE
)
Arguments
cifti_fnames |
Vector of file paths of CIFTI-format fMRI timeseries (*.dtseries.nii) for which to calculate group ICA |
subjects |
Use this argument if some subjects have more than one scan.
This is a numeric or factor vector the same length as |
brainstructures |
Character vector indicating which brain structure(s)
to obtain: |
num_PCs |
Maximum number of PCs to retain in initial subject-level PCA |
num_ICs |
Number of independent components to identify. |
max_rows_GPCA |
The maximum number of rows for the matrix on which group
level PCA will be performed. This matrix is the result of temporal concatenation
and contains |
GSR , scale , scale_sm_FWHM , TR , hpf |
Center BOLD columns, scale by the
standard deviation, and detrend voxel timecourses? See
|
verbose |
If |
out_fname |
(Optional) If not specified, a xifti object will be returned but the GICA maps will not be written to a CIFTI file. |
surfL |
(Optional) File path to a surface GIFTI for the left cortex. If provided, will be part of xifti result object for visualization in R. Will also be used to perform any smoothing. |
surfR |
(Optional) File path to a surface GIFTI for the right cortex. If provided, will be part of xifti result object for visualization in R. Will also be used to perform any smoothing. |
smooth |
Smooth the CIFTI data prior to reading in each file? Default:
|
smooth_surf_FWHM , smooth_vol_FWHM , smooth_zeroes_as_NA , smooth_subcortical_merged |
See |
Value
out_fname
if a file was written, or the GICA as a "xifti"
object
if not.
Half log determinant
Description
Computes half log determinant of X
, by sum(log(diag(chol(X))))
.
Usage
halflogdetX(X)
Arguments
X |
A numeric matrix |
Value
The half log determinant of X
.
hpf
Description
hpf
Arguments
hpf |
The frequency at which to apply a highpass filter to the data
during pre-processing, in Hertz. Default: The highpass filter serves to detrend the data, since low-frequency variance is associated with noise. Highpass filtering is accomplished by nuisance regression of discrete cosine transform (DCT) bases. Note the |
Compute likelihood in SPDE model for ESS estimation
Description
Compute likelihood in SPDE model for ESS estimation
Usage
lik(theta, Y, G, C, ind = NULL)
Arguments
theta |
Value of hyperparameters |
Y |
Data vector |
G |
SPDE G matrix |
C |
SPDE C matrix |
ind |
Indices of data locations in the mesh |
Value
Log likelihood value
Kappa log-likelihood
Description
Applicable to a single latent field, or multiple latent fields if common smoothness is assumed
Usage
loglik_kappa_est(par, delta, D_diag, mesh, C1 = 1/(4 * pi), Q = NULL)
Arguments
par |
Vector of length two containing values of log kappa and log residual variance at which to compute log likelihood |
delta |
Estimate of delta (subject effect or deviation) |
D_diag |
Diagonal values of D matrix (template standard deviations) |
mesh |
Object of class "templateICA_mesh" containing the triangular mesh (see |
C1 |
For the unit variance case, |
Q |
Equal to the number of ICs for the common smoothness model, or NULL for the IC-specific smoothness model |
Details
Compute log-likelihood of kappa given an initial estimate of delta
Value
Value of negative log likelihood
Make permutation matrix
Description
Create permutation matrix P to regroup elements of s by locations instead of by ICs
Usage
make_Pmat(Q, nvox)
Arguments
Q |
The number of template ICs |
nvox |
The number of spatial locations ( |
Details
If s=(s1,...,sQ) is grouped by ICs 1,...Q, then Ps=(s(1),...,s(nvox)) is grouped by locations 1,...,nvox
Value
P Permutation matrix size QVxQV
Create a mask based on vertices that are invalid
Description
Create a mask based on vertices that are invalid
Usage
make_mask(BOLD, meanTol = -Inf, varTol = 1e-06, verbose = TRUE)
Arguments
BOLD |
A |
meanTol , varTol |
Tolerance for mean and variance of each data location.
Locations which do not meet these thresholds are masked out of the analysis.
Defaults: |
verbose |
Print messages counting how many locations are removed? |
Value
A logical vector indicating valid vertices
Make INLA mesh from "surf"
object
Description
Create INLA mesh and observation weight matrix based on a "surf"
object
Usage
make_mesh(surf = NULL, inds_data = NULL, inds_mesh = NULL)
Arguments
surf |
|
inds_data |
Subset of vertices to include in analysis, e.g. non-medial wall locations. |
inds_mesh |
Subset of vertices to retain in mesh, e.g. non-medial wall
locations. Must be a superset of |
Value
List containing INLA mesh, observation weight matrix A for translating between mesh locations and original data locations, the brain mask used to create the mesh, and the number of original and mesh data locations.
Make 2D INLA mesh
Description
Create INLA mesh and observation weight matrix based on a binary brain mask
Usage
make_mesh_2D(mask)
Arguments
mask |
Brain mask (matrix of 0 and 1 or |
Details
This function requires the INLA
package, which is not a CRAN
package. See https://www.r-inla.org/download-install for easy
installation instructions.
Value
List containing INLA mesh, observation weight matrix A for translating between mesh locations and original data locations, the brain mask used to create the mesh, and the number of original and mesh data locations.
Normalize BOLD data
Description
Center the data across space and/or time, detrend, and scale, in that order. For dual regression, row centering is required and column centering is not recommended. Scaling and detrending depend on the user preference.
Usage
norm_BOLD(
BOLD,
center_rows = TRUE,
center_cols = FALSE,
scale = c("local", "global", "none"),
scale_sm_xifti = NULL,
scale_sm_FWHM = 2,
scale_sm_xifti_mask = NULL,
TR = NULL,
hpf = 0.01
)
Arguments
BOLD |
fMRI numeric data matrix ( |
center_rows , center_cols |
Center BOLD data across rows (each data
location's time series) or columns (each time point's image)? Default:
|
scale |
|
scale_sm_xifti , scale_sm_FWHM |
Only applies if |
scale_sm_xifti_mask |
For local scaling with smoothing, the data must be unmasked to be mapped back to the surface. So if the data are masked, provide the mask here. |
TR |
The temporal resolution of the data, i.e. the time between volumes,
in seconds. |
hpf |
The frequency at which to apply a highpass filter to the data
during pre-processing, in Hertz. Default: The highpass filter serves to detrend the data, since low-frequency variance is associated with noise. Highpass filtering is accomplished by nuisance regression of discrete cosine transform (DCT) bases. Note the |
Value
Normalized BOLD data matrix (V \times T
)
Orthonormalizes a square, invertible matrix
Description
Orthonormalizes a square, invertible matrix
Usage
orthonorm(X)
Arguments
X |
A square matrix to be orthonormalized. |
Details
Y is orthonormal if $YY'=Y'Y=I$. Orthonormalization of X is given by $X (X'X)^(-.5)$.
Value
X after orthonormalization
Plot template
Description
Plot template
Usage
## S3 method for class 'tICA.cifti'
plot(x, stat = c("mean", "se", "both"), ...)
Arguments
x |
The result of |
stat |
|
... |
Additional arguments to |
Value
The plot
Plot template
Description
This feature is not supported yet.
Usage
## S3 method for class 'tICA.matrix'
plot(x, ...)
Arguments
x |
The result of |
... |
Additional arguments |
Value
Nothing, because an error is raised.
Plot template
Description
Plot template
Usage
## S3 method for class 'tICA.nifti'
plot(
x,
stat = c("mean", "se"),
plane = c("axial", "sagittal", "coronal"),
n_slices = 9,
slices = NULL,
...
)
Arguments
x |
The result of |
stat |
|
plane , n_slices , slices |
Anatomical plane and which slice indices to show. Default: 9 axial slices. |
... |
Additional arguments |
Value
The plot
Plot activations
Description
Plot activations
Usage
## S3 method for class 'tICA_act.cifti'
plot(x, stat = c("active", "pvals", "pvals_adj", "tstats", "se"), ...)
Arguments
x |
The activations from |
stat |
|
... |
Additional arguments to |
Value
The activations plot
Plot template
Description
Plot template
Usage
## S3 method for class 'template.cifti'
plot(
x,
stat = c("both", "mean", "sd", "var"),
var_method = c("non-negative", "unbiased"),
...
)
Arguments
x |
The template from |
stat |
|
var_method |
|
... |
Additional arguments to |
Value
The plot
Plot template
Description
Plot template
Usage
## S3 method for class 'template.gifti'
plot(
x,
stat = c("both", "mean", "sd", "var"),
var_method = c("non-negative", "unbiased"),
...
)
Arguments
x |
The template from |
stat |
|
var_method |
|
... |
Additional arguments to |
Value
The plot
Plot template
Description
Plot template
Usage
## S3 method for class 'template.matrix'
plot(x, ...)
Arguments
x |
The template from |
... |
Additional arguments |
Value
The plot
Plot template
Description
Based on oro.nifti::image
.
Usage
## S3 method for class 'template.nifti'
plot(
x,
stat = c("mean", "sd", "var"),
plane = c("axial", "sagittal", "coronal"),
n_slices = 9,
slices = NULL,
var_method = c("non-negative", "unbiased"),
...
)
Arguments
x |
The template from |
stat |
|
plane , n_slices , slices |
Anatomical plane and which slice indices to show. Default: 9 axial slices. |
var_method |
|
... |
Additional arguments to |
Details
Consider using struct_template
to obtain the 3D volumes to plot with a different
viewer function (e.g. from oro.nifti
) if desired.
Value
The plot
Estimate residual autocorrelation for prewhitening
Description
Estimate residual autocorrelation for prewhitening
Usage
pw_estimate(A, ar_order, aic = FALSE)
Arguments
A |
Estimated A matrix (T x Q) |
ar_order , aic |
Order of the AR model used to prewhiten the data at each location.
If |
Value
Estimated AR coefficients and residual variance at every vertex
Remove brain structure from CIFTI template
Description
Remove a brain structure from a CIFTI template
Usage
removebs_template(x, remove = NULL)
Arguments
x |
The |
remove |
|
Resample CIFTI template
Description
Resample a CIFTI template to a new spatial resolution.
Usage
resample_template(x, resamp_res, verbose = FALSE)
Arguments
x |
The |
resamp_res |
The new resampling resolution. |
verbose |
Give occasional updates? Default: |
Value
The resampled "template.cifti"
object.
Remove nuisance ICs from data
Description
Subtract estimated nuisance ICs from data matrix. If the number of nuisance ICs is not provided, will estimate using PESEL (the nuisance ICs are a rotation of the nuisance PCs).
Usage
rm_nuisIC(
BOLD,
DR = NULL,
template_mean = NULL,
Q2 = NULL,
Q2_max = NULL,
checkRowCenter = TRUE,
verbose = FALSE,
return_Q2 = FALSE
)
Arguments
BOLD |
the row-centered |
DR , template_mean |
We need an initial estimate of the group ICs, so
that we can avoid removing them during removal of the estimated noise ICs.
Provide either |
Q2 |
The number of nuisance ICs. If |
Q2_max |
If |
checkRowCenter |
Check row means, and raise an error if they are
nonzero? Default: |
verbose |
If |
return_Q2 |
Return (estimated) |
Value
The V
by T
data with the estimated nuisance ICs
subtracted from it. If return_Q2
, a list of length two: the second
entry will be Q2
.
scale
Description
scale
Arguments
scale |
|
Compute matrix square root of X'X
Description
Compute matrix square root of X'X
Usage
sqrt_XtX(X, inverse = FALSE)
Arguments
X |
A numerical matrix |
inverse |
if inverse=TRUE, compute inverse of square root |
Value
A matrix equalling the (inverse) matrix square root of X'X
Apply data structure to templates
Description
Apply data structure to templates
Usage
struct_template(
template,
FORMAT,
mask_input,
params,
dat_struct,
GICA_parc_table
)
Arguments
template |
The template |
FORMAT |
"CIFTI", "GIFTI", "NIFTI", or "DATA" |
mask_input |
The input mask |
params |
The params |
dat_struct |
The data structure |
Summarize a "tICA.cifti"
object
Description
Summary method for class "tICA.cifti"
Usage
## S3 method for class 'tICA.cifti'
summary(object, ...)
## S3 method for class 'summary.tICA.cifti'
print(x, ...)
## S3 method for class 'tICA.cifti'
print(x, ...)
Arguments
object |
Object of class |
... |
further arguments passed to or from other methods. |
x |
The result of |
Value
A list summarizing of the results of the templateICA analysis.
Nothing, invisibly.
Nothing, invisibly.
Summarize a "tICA.matrix"
object
Description
Summary method for class "tICA.matrix"
Usage
## S3 method for class 'tICA.matrix'
summary(object, ...)
## S3 method for class 'summary.tICA.matrix'
print(x, ...)
## S3 method for class 'tICA.matrix'
print(x, ...)
Arguments
object |
Object of class |
... |
further arguments passed to or from other methods. |
x |
The template from |
Value
A list summarizing of the results of the templateICA analysis.
Nothing, invisibly.
Nothing, invisibly.
Summarize a "tICA.nifti"
object
Description
Summary method for class "tICA.nifti"
Usage
## S3 method for class 'tICA.nifti'
summary(object, ...)
## S3 method for class 'summary.tICA.nifti'
print(x, ...)
## S3 method for class 'tICA.nifti'
print(x, ...)
Arguments
object |
Object of class |
... |
further arguments passed to or from other methods. |
x |
The template from |
Value
A list summarizing of the results of the templateICA analysis.
Nothing, invisibly.
Nothing, invisibly.
Summarize a "tICA_act.cifti"
object
Description
Summary method for class "tICA_act.cifti"
Usage
## S3 method for class 'tICA_act.cifti'
summary(object, ...)
## S3 method for class 'summary.tICA_act.cifti'
print(x, ...)
## S3 method for class 'tICA_act.cifti'
print(x, ...)
Arguments
object |
Object of class |
... |
further arguments passed to or from other methods. |
x |
The activations from |
Value
A list summarizing the data and results for the activations analysis.
Nothing, invisibly.
Nothing, invisibly.
Summarize a "tICA_act.matrix"
object
Description
Summary method for class "tICA_act.matrix"
Usage
## S3 method for class 'tICA_act.matrix'
summary(object, ...)
## S3 method for class 'summary.tICA_act.matrix'
print(x, ...)
## S3 method for class 'tICA_act.matrix'
print(x, ...)
Arguments
object |
Object of class |
... |
further arguments passed to or from other methods. |
x |
The activations from |
Value
A list summarizing the data and results for the activations analysis.
Nothing, invisibly.
Nothing, invisibly.
Summarize a "tICA_act.nifti"
object
Description
Summary method for class "tICA_act.nifti"
Usage
## S3 method for class 'tICA_act.nifti'
summary(object, ...)
## S3 method for class 'summary.tICA_act.nifti'
print(x, ...)
## S3 method for class 'tICA_act.nifti'
print(x, ...)
Arguments
object |
Object of class |
... |
further arguments passed to or from other methods. |
x |
The activations from |
Value
A list summarizing the data and results for the activations analysis.
Nothing, invisibly.
Nothing, invisibly.
Summarize a "template.cifti"
object
Description
Summary method for class "template.cifti"
Usage
## S3 method for class 'template.cifti'
summary(object, ...)
## S3 method for class 'summary.template.cifti'
print(x, ...)
## S3 method for class 'template.cifti'
print(x, ...)
Arguments
object |
Object of class |
... |
further arguments passed to or from other methods. |
x |
The template from |
Value
A list summarizing the template: data dimensions, options used for template estimation, etc.
Nothing, invisibly.
Nothing, invisibly.
Summarize a "template.gifti"
object
Description
Summary method for class "template.gifti"
Usage
## S3 method for class 'template.gifti'
summary(object, ...)
## S3 method for class 'summary.template.gifti'
print(x, ...)
## S3 method for class 'template.gifti'
print(x, ...)
Arguments
object |
Object of class |
... |
further arguments passed to or from other methods. |
x |
The template from |
Value
A list summarizing the template: data dimensions, options used for template estimation, etc.
Nothing, invisibly.
Nothing, invisibly.
Summarize a "template.matrix"
object
Description
Summary method for class "template.matrix"
Usage
## S3 method for class 'template.matrix'
summary(object, ...)
## S3 method for class 'summary.template.matrix'
print(x, ...)
## S3 method for class 'template.matrix'
print(x, ...)
Arguments
object |
Object of class |
... |
further arguments passed to or from other methods. |
x |
The template from |
Value
A list summarizing the template: data dimensions, options used for template estimation, etc.
Nothing, invisibly.
Nothing, invisibly.
Summarize a "template.nifti"
object
Description
Summary method for class "template.nifti"
Usage
## S3 method for class 'template.nifti'
summary(object, ...)
## S3 method for class 'summary.template.nifti'
print(x, ...)
## S3 method for class 'template.nifti'
print(x, ...)
Arguments
object |
Object of class |
... |
further arguments passed to or from other methods. |
x |
The template from |
Value
A list summarizing the template: data dimensions, options used for template estimation, etc.
Nothing, invisibly.
Nothing, invisibly.
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",
covariates = NULL,
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, 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 |
tvar_method |
Which calculation of the template variance to use:
|
scale |
|
scale_sm_surfL , scale_sm_surfR , scale_sm_FWHM |
Only applies if
If If To create a |
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
|
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 |
TR , hpf |
These arguments control detrending. Note that if multiple |
GSR |
Center BOLD across columns (each image)? This
is equivalent to performing global signal regression. Default:
|
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 If The defaults for both arguments is |
covariates |
Numeric vector of covariates to take into account for model
estimation. Names should give the name of each variable. The covariates must
match those of the template. Default: |
brainstructures |
Only applies if the entries of |
mask |
Required if and only if the entries of |
time_inds |
Subset of fMRI BOLD volumes to include in analysis, as a
vector of numeric integers. If |
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: |
spatial_model |
Should spatial modeling be performed? If If If If |
resamp_res |
Only applies if |
rm_mwall |
Only applies if |
reduce_dim |
Reduce the temporal dimension of the data using PCA?
Default: |
method_FC |
Variational Bayes (VB) method for FC template ICA model:
|
maxiter |
Maximum number of EM or VB iterations. Default: |
miniter |
Minimum number of EM or VB iterations. Default: |
epsilon |
Smallest proportion change between iterations. Default:
|
kappa_init |
Starting value for kappa. Default: |
usePar |
Parallelize the computation? Default: |
PW |
Prewhiten to account for residual autocorrelation? Default: |
verbose |
If |
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)
Update A for VB FC Template ICA using IW prior on FC
Description
Update A for VB FC Template ICA using IW prior on FC
Usage
update_A(
mu_tau2,
mu_S,
E_SSt,
BOLD,
ntime,
nICs,
nvox,
u_samps,
template_FC,
usePar = TRUE,
final = FALSE
)
Arguments
mu_tau2 , mu_S , E_SSt |
Most recent estimates of posterior moments for these variables. |
BOLD |
( |
ntime , nICs , nvox |
Number of timepoints, number of ICs, number of locations |
u_samps |
Samples from Gamma for multivariate t prior on A |
template_FC |
IW parameters for FC template |
usePar |
Parallelize the computation? Default: |
final |
If TRUE, return cov_A. Default: |
Value
List of length two: mu_A
(TxQ) and E_AtA
(QxQ).
Update A for VB FC Template ICA using Cholesky prior for FC
Description
Update A for VB FC Template ICA using Cholesky prior for FC
Usage
update_A_Chol(
mu_tau2,
mu_S,
E_SSt,
BOLD,
ntime,
nICs,
nvox,
template_FC,
final = FALSE,
exact = FALSE,
usePar = TRUE,
verbose = FALSE
)
Arguments
mu_tau2 , mu_S , E_SSt |
Most recent estimates of posterior moments for these variables. |
BOLD |
( |
ntime , nICs , nvox |
Number of timepoints, number of ICs, number of locations |
template_FC |
IW parameters for FC template |
final |
If TRUE, return cov_A. Default: |
exact |
If FALSE, at intermediate steps (final = |
usePar |
Parallelize the computation? Default: |
verbose |
If |
Value
List of length two: mu_A
(TxQ) and E_AtA
(QxQ).
Update S for VB FC Template ICA
Description
Update S for VB FC Template ICA
Usage
update_S(
mu_tau2,
mu_A,
E_AtA,
D_inv,
D_inv_S,
BOLD,
nICs,
nvox,
ntime,
final = FALSE
)
Arguments
mu_tau2 , mu_A , E_AtA |
Most recent posterior estimates |
D_inv , D_inv_S |
Some pre-computed quantities. |
BOLD |
( |
nICs , nvox , ntime |
Number of ICs, number of data locations, and time series length |
final |
If TRUE, return cov_S. Default: |
Value
List of length three: mu_S
(QxV), E_SSt
(QxQ), and cov_S
(QxQxV).
Update tau for VB FC Template ICA
Description
Update tau for VB FC Template ICA
Usage
update_tau2(BOLD, BOLD2, mu_A, E_AtA, mu_S, E_SSt, prior_params, ntime, nvox)
Arguments
BOLD |
( |
BOLD2 |
A precomputed quantity, |
mu_A , E_AtA , mu_S , E_SSt |
Current posterior estimates |
prior_params |
Alpha and beta parameters of IG prior on |
ntime , nvox |
Number of timepoints in data and the number of data locations. |
Value
List of length two: alpha1
and beta1
.
varTol
Description
varTol
Arguments
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: |
Compute the error between empirical and theoretical variance of covariance matrix elements
Description
Compute the error between empirical and theoretical variance of covariance matrix elements
Usage
var_sq_err(nu, p, var_ij, xbar_ij, xbar_ii, xbar_jj)
Arguments
nu |
Inverse Wishart degrees of freedom parameter |
p |
Matrix dimension for IW distribution |
var_ij |
Empirical between-subject variance of covariance matrices at element (i,j) |
xbar_ij |
Empirical mean of covariance matrices at element (i,j) |
xbar_ii |
Empirical mean of covariance matrices at the ith diagonal element |
xbar_jj |
Empirical mean of covariance matrices at the jth diagonal element |
Value
Squared difference between the empirical and theoretical IW variance of covariance matrices at element (i,j)
Compute the overall error between empirical and theoretical variance of CORRELATION matrix elements
Description
Compute the overall error between empirical and theoretical variance of CORRELATION matrix elements
Usage
var_sq_err_constrained(nu, p, var, xbar, M = 10000)
Arguments
nu |
Inverse Wishart degrees of freedom parameter |
p |
Matrix dimension for IW distribution |
var |
Empirical between-subject variances of CORRELATION matrix (upper triangle) |
xbar |
Empirical mean of CORRELATION matrix (upper triangle) |
M |
Penalty to assign if theoretical variance is smaller than empirical variance |
Value
Sum of squared difference between the empirical and theoretical IW variance of CORRELATION matrix, but with constraint that theoretical variances must not be smaller than empirical variances