Title: | Hemodynamic Response Function |
---|---|
Description: | Computes the hemodynamic response function (HRF) for task functional magnetic resonance imaging (fMRI) data. Also includes functions for constructing a design matrix from task fMRI event timings, and for comparing multiple design matrices in a general linear model (GLM). A wrapper function is provided for GLM analysis of CIFTI-format data. Lastly, there are supporting functions which provide visual summaries of the HRFs and design matrices. |
Authors: | Amanda Mejia [aut, cre],
Damon Pham [ctb] |
Maintainer: | Amanda Mejia <[email protected]> |
License: | GPL-3 |
Version: | 0.1.3 |
Built: | 2025-04-01 05:33:58 UTC |
Source: | https://github.com/mandymejia/hrf |
aic
aic |
(For prewhitening) Use the Akaike information criterion (AIC) to
select AR model orders between |
ar_order
ar_order |
(For prewhitening) The order of the autoregressive (AR) model
to use for prewhitening. If For multi-session modeling, note that a single AR model is used; its coefficients will be the average estimate from each session. |
ar_smooth
ar_smooth |
(For prewhitening) The FWHM parameter for spatially
smoothing the coefficient estimates for the AR model to use for
prewhitening. Recall that
|
BOLD
BOLD |
fMRI timeseries data in CIFTI format ("*.dtseries.nii").
For single-session analysis this can be a file path to a CIFTI file or a
If |
brainstructures
brainstructures |
Character vector indicating which brain structure(s)
of |
Take the central derivative of numeric vectors by averaging the forward and backward differences.
cderiv(x)
cderiv(x)
x |
A numeric matrix, or a vector which will be converted to a single-column matrix. |
A matrix or vector the same dimensions as x
, with the
derivative taken for each column of x
. The first and last rows may
need to be deleted, depending on the application.
x <- cderiv(seq(5)) stopifnot(all(x == c(.5, 1, 1, 1, .5)))
x <- cderiv(seq(5)) stopifnot(all(x == c(.5, 1, 1, 1, .5)))
Connectome Workbench
This function uses a system wrapper for the 'wb_command' executable. The user must first download and install the Connectome Workbench, available from https://www.humanconnectome.org/software/get-connectome-workbench .
design
design |
A numeric matrix or |
Mask out data locations that are invalid (missing data, low mean, or low variance) for any session.
do_QC(BOLD, meanTol = 1e-06, varTol = 1e-06, verbose = TRUE)
do_QC(BOLD, meanTol = 1e-06, varTol = 1e-06, verbose = TRUE)
BOLD |
A session-length list of |
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?
Default: |
A logical vector indicating locations that are valid across all sessions.
nT <- 30 nV <- 400 BOLD1 <- matrix(rnorm(nT*nV), nrow=nT) BOLD1[,seq(30,50)] <- NA BOLD2 <- matrix(rnorm(nT*nV), nrow=nT) BOLD2[,65] <- BOLD2[,65] / 1e10 BOLD <- list(sess1=BOLD1, sess2=BOLD2) do_QC(BOLD)
nT <- 30 nV <- 400 BOLD1 <- matrix(rnorm(nT*nV), nrow=nT) BOLD1[,seq(30,50)] <- NA BOLD2 <- matrix(rnorm(nT*nV), nrow=nT) BOLD2[,65] <- BOLD2[,65] / 1e10 BOLD <- list(sess1=BOLD1, sess2=BOLD2) do_QC(BOLD)
faces
faces |
An |
field_names
field_names |
(Optional) Names of fields represented in design matrix. |
hpf
hpf |
Add DCT bases to Using at least two DCT bases is as sufficient for detrending as using linear
and quadratic drift terms in the nuisance matrix. So if DCT detrending is
being used here, there is no need to add linear and quadratic drift terms to
|
Calculate the HRF from a time vector and parameters, or its derivative with respect to delay or dispersion.
HRF_calc( t, deriv = 0, a1 = 6, b1 = 1, a2 = 16/6 * a1 * sqrt(b1), b2 = b1, c = 1/6, o = 0 )
HRF_calc( t, deriv = 0, a1 = 6, b1 = 1, a2 = 16/6 * a1 * sqrt(b1), b2 = b1, c = 1/6, o = 0 )
t |
time vector (in units of seconds) |
deriv |
|
a1 |
delay of response. Default: |
b1 |
response dispersion. Default: |
a2 |
delay of undershoot. Default: |
b2 |
dispersion of undershoot. Default: |
c |
scale of undershoot. Default: |
o |
onset of response. Default: |
HRF vector (or dHRF, or d2HRF) corresponding to time vector t
samples_per_sec <- 200 nsec <- 50 HRF_calc(seq(nsec*samples_per_sec)/samples_per_sec)
samples_per_sec <- 200 nsec <- 50 HRF_calc(seq(nsec*samples_per_sec)/samples_per_sec)
Calculate the HRF from a time vector and parameters. Optionally compute the first or second derivative of the HRF instead. Form of HRF is similar to SPM but here the response and undershoot are scaled so the difference of the HRFs peaks at 1 and -c
HRF_main(t, a1 = 6, b1 = 1, a2 = NULL, b2 = NULL, c = 1/6, o = 0)
HRF_main(t, a1 = 6, b1 = 1, a2 = NULL, b2 = NULL, c = 1/6, o = 0)
t |
time vector (in seconds). Must be equally spaced. |
a1 |
delay of response. Default: |
b1 |
response dispersion. Default: |
a2 |
delay of undershoot. Default: |
b2 |
dispersion of undershoot. Default: |
c |
scale of undershoot. Default: |
o |
onset of response (in seconds). Default: |
HRF vector corresponding to time vector t
upsample <- 100 HRF_main(seq(0, 30, by=1/upsample))
upsample <- 100 HRF_main(seq(0, 30, by=1/upsample))
Calculate the HRF from a time vector and parameters. Optionally compute the first or second derivative of the HRF instead.
HRF96(t, deriv = 0, a1 = 6, b1 = 0.9, a2 = 12, b2 = 0.9, c = 0.35)
HRF96(t, deriv = 0, a1 = 6, b1 = 0.9, a2 = 12, b2 = 0.9, c = 0.35)
t |
time vector |
deriv |
|
a1 |
delay of response. Default: |
b1 |
response dispersion. Default: |
a2 |
delay of undershoot. Default: |
b2 |
dispersion of undershoot. Default: |
c |
scale of undershoot. Default: |
HRF vector (or dHRF, or d2HRF) corresponding to time
upsample <- 100 HRF96(seq(0, 30, by=1/upsample))
upsample <- 100 HRF96(seq(0, 30, by=1/upsample))
Make the design matrix for the GLM, from the task information.
make_design( EVs, nTime, TR, dHRF = 0, upsample = 100, onset = NULL, offset = NULL, scale_design = TRUE, onsets_sep = FALSE, offsets_sep = FALSE, verbose = TRUE, ... )
make_design( EVs, nTime, TR, dHRF = 0, upsample = 100, onset = NULL, offset = NULL, scale_design = TRUE, onsets_sep = FALSE, offsets_sep = FALSE, verbose = TRUE, ... )
EVs |
The explanatory variables i.e. the task stimulus information,
from which a design matrix will be constructed. This is a list where each
entry represents a task as a matrix of onsets (first column) and durations
(second column) for each stimuli (each row) of the task, in seconds. List
names should be the task names. An example of a properly-formatted |
nTime |
the number of timepoints (volumes) in the task fMRI data. |
TR |
the temporal resolution of the data, in seconds. |
dHRF |
Controls the extent of HRF derivatives modeling. Set to If there are several tasks and |
upsample |
Upsample factor for convolving stimulus boxcar or stick
function with canonical HRF. Default: |
onset , offset
|
Add task regressors indicating the onset and/or offset of
each event block? Provide the names of the tasks as a character vector. All
onsets (or offsets) across the specified tasks will be represented by one
additional column in the design matrix. The task names must match the names
of Onsets/offset modeling is only compatible with a block design experiment.
An error will be raised if the events in |
scale_design |
Scale the columns of the design matrix? Default:
|
onsets_sep , offsets_sep
|
Model the onsets ( |
verbose |
Print diagnostic messages? Default: |
... |
Additional arguments to |
A "BfMRI_design"
object: a list with elements
The volumes by fields design matrix. Column names are field names.
The name of each task from the provided onsets.
The input dHRF
parameter.
Additional HRF modeling results.
EVs <- list(taskA=cbind(on=c(1,9,17), dr=rep(1,3)), taskB=cbind(on=c(3,27), dr=rep(5,2))) TR <- .72 nTime <- ceiling(65/TR) make_design(EVs, nTime, TR)
EVs <- list(taskA=cbind(on=c(1,9,17), dr=rep(1,3)), taskB=cbind(on=c(3,27), dr=rep(5,2))) TR <- .72 nTime <- ceiling(65/TR) make_design(EVs, nTime, TR)
mask: vertices
mask |
A length |
mean and variance tolerance
meanTol , varTol
|
Tolerance for mean and variance of each data location.
Locations which do not meet these thresholds are masked out of the analysis.
Default: |
Performs classical Bayesian GLM for task fMRI activation with CIFTI-format data, evaluating multiple design matrices. Includes the pre-processing steps of nuisance regression. Supports single-session analysis only.
multiGLM( BOLD, design, brainstructures = c("left", "right"), TR = NULL, resamp_res = 10000, hpf = NULL, nuisance = NULL, design_canonical = NULL, verbose = 1, meanTol = 1e-06, varTol = 1e-06 )
multiGLM( BOLD, design, brainstructures = c("left", "right"), TR = NULL, resamp_res = 10000, hpf = NULL, nuisance = NULL, design_canonical = NULL, verbose = 1, meanTol = 1e-06, varTol = 1e-06 )
BOLD |
fMRI timeseries data in CIFTI format ("*.dtseries.nii").
For single-session analysis this can be a file path to a CIFTI file or a
If |
design |
A 3D numeric array that is locations by fields by designs. |
brainstructures |
Character vector indicating which brain structure(s)
of |
TR |
Temporal resolution of the data, in seconds. |
resamp_res |
For cortex spatial model. The number of vertices to which
each cortical surface should be resampled, or For computational feasibility, a value of |
hpf |
Add DCT bases to Using at least two DCT bases is as sufficient for detrending as using linear
and quadratic drift terms in the nuisance matrix. So if DCT detrending is
being used here, there is no need to add linear and quadratic drift terms to
|
nuisance |
(Optional) A Detrending/high-pass filtering is accomplished by adding DCT bases to the
nuisance matrix; see the parameters Do not add spike regressors for scrubbing to the |
design_canonical |
TO DO |
verbose |
|
meanTol , varTol
|
Tolerance for mean and variance of each data location.
Locations which do not meet these thresholds are masked out of the analysis.
Default: |
An object of class "mGLM"
: a list with elements
data.frame
summarizing the spatial features of each brain structure modeled.
data.frame
with the name
, related task
, and HRF_order
of each field.
This function uses a system wrapper for the 'wb_command' executable. The user must first download and install the Connectome Workbench, available from https://www.humanconnectome.org/software/get-connectome-workbench .
Performs classical GLM for task fMRI activation, comparing multiple designs
multiGLM_fun( BOLD, design, nuisance = NULL, design_canonical = NULL, verbose = 1, meanTol = 1e-06, varTol = 1e-06 )
multiGLM_fun( BOLD, design, nuisance = NULL, design_canonical = NULL, verbose = 1, meanTol = 1e-06, varTol = 1e-06 )
BOLD , design , nuisance
|
Session-length list of numeric matrices/arrays, each with volumes along the first dimension. |
design_canonical |
TO DO |
verbose |
|
meanTol , varTol
|
Tolerance for mean, variance and SNR of each data location.
Locations which do not meet these thresholds are masked out of the analysis.
Default: |
A list with elements
...
...
...
nuisance
nuisance |
(Optional) A Detrending/high-pass filtering is accomplished by adding DCT bases to the
nuisance matrix; see the parameters Do not add spike regressors for scrubbing to the |
Plot design matrix
Plot design with lineplot
Plot design with imageplot
plot_design(design, method = c("lineplot", "imageplot"), ...) plot_design_line( design, colors = "Set1", linetype = "solid", linewidth = 0.7, alpha = 0.8 ) plot_design_image(design)
plot_design(design, method = c("lineplot", "imageplot"), ...) plot_design_line( design, colors = "Set1", linetype = "solid", linewidth = 0.7, alpha = 0.8 ) plot_design_image(design)
design |
The timepoints by fields design matrix or data.frame. |
method |
|
... |
Additional arguments to |
colors |
The name of a ColorBrewer palette (see
RColorBrewer::brewer.pal.info and colorbrewer2.org), the name of a
viridisLite palette, or a character vector of colors. Default:
|
linetype , linewidth , alpha
|
Parameters for |
A ggplot
A ggplot
A ggplot
view_xifti
to plot a "BGLM"
objectS3 method: use view_xifti
to plot a "BGLM"
object
## S3 method for class 'BfMRI_design' plot(x, ...)
## S3 method for class 'BfMRI_design' plot(x, ...)
x |
An object of class "BfMRI_design". |
... |
Additional arguments to |
Result of the call to plot_design
resamp_res
resamp_res |
For cortex spatial model. The number of vertices to which
each cortical surface should be resampled, or For computational feasibility, a value of |
scale_BOLD
scale_BOLD |
Controls scaling the BOLD response at each location.
|
scrub
scrub |
(Optional) A The spike regressors will be included in the nuisance
regression, and afterwards the timepoints indicated in |
session_names
session_names |
The names of the task-fMRI |
"BfMRI_design"
objectSummary method for class "BfMRI_design"
## S3 method for class 'BfMRI_design' summary(object, ...) ## S3 method for class 'summary.BfMRI_design' print(x, ...) ## S3 method for class 'BfMRI_design' print(x, ...)
## S3 method for class 'BfMRI_design' summary(object, ...) ## S3 method for class 'summary.BfMRI_design' print(x, ...) ## S3 method for class 'BfMRI_design' print(x, ...)
object |
Object of class |
... |
further arguments passed to or from other methods. |
x |
Object of class |
A "summary.BfMRI_design"
object, a list summarizing the
properties of object
.
NULL
, invisibly.
NULL
, invisibly.
surfaces
surfL , surfR
|
For cortex spatial model. Left and right cortex surface
geometry in GIFTI format ("*.surf.gii"). These can be a file path to
a GIFTI file or a Surfaces can alternatively be provided through the |
verbose
verbose |
|