AFNI and other fMRI analysis packages have robust and efficient methods for estimating voxelwise regression models. Therefore, it may be beneficial to construct a regression model in R using fmrireg and translate it so that it can be executed using one of these packages. Here we provide a translation mechanism from an fmri_model
object constructed with fmrireg
to syntax and assocaited file required for execution using AFNI's 3dDeconvolve program.
library(tibble) library(fmrireg)
Lets begin again with a simple fMRI design.
cond <- c("face", "scene", "tool", "object") NSTIM <- length(cond)*4 simple_design <- data.frame(stim=factor(sample(rep(cond, 4))), ISI=sample(4:7, NSTIM, replace=TRUE), run=rep(1, NSTIM), trial=factor(1:NSTIM))
Now we add onset information, construct a sampling_frame
, create a contrast, and then an event_model
:
simple_design$onset <- cumsum(simple_design$ISI+2) -2 sframe <- sampling_frame(blocklens=70, TR=2) con1 <- pair_contrast(~ stim == "face", ~stim == "scene", name="face_scene") emodel <- event_model(onset ~ hrf(stim, contrasts=con1), data=simple_design, block = ~ run, sampling_frame=sframe) plot(emodel)
We construct a baseline_model
using a B-spline basis:
bmodel <- baseline_model(basis="bs", degree=5, sframe=sframe) print(bmodel) plot(bmodel)
We construct an fmri_model
:
fmodel <- fmri_model(emodel, bmodel)
Now we need to specify the data that the model will be estimated on. Let us pretend that we have a single 4d NIfTI file called "scan01.nii" and a mask file called "mask.nii".
dset <- fmri_dataset(scans="scan01.nii", mask="mask.nii", TR=2, run_length=70, event_table=simple_design, base_path=".")
We are now ready to construct an AFNI model specification. Note that all contrasts in the model will automatically be converted to AFNI-style general linear tests (GLTs).
alm <- afni_lm(fmodel, dset) print(alm)
Also, note that since we include a set of b-spline nuisance parameters in our model, polort
is set to have no baseline regressors (polort = -1).
We change that if we like:
alm <- afni_lm(fmodel, dset, polort=2) print(alm)
But this would essentially add two sets of drift regressors, which would be bad.
To send other options to the 3dDeconvolve
command we can add them to the options
argument, e.g.
alm <- afni_lm(fmodel, dset, options=list(tout=FALSE, fout=FALSE)) print(alm)
To execute the external 3dDeconvolve
command on the system, we do as follows:
#run(alm, outdir="glm_out")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.