Including per-stim duration for -stim_times_IM and GAM

Hi AFNI folks,

I am running task fMRI functional connectivity analyses. I am using the combination of 3dDeconvolve (+ stim_times_IM) design matrix generation and 3dLSS beta-series as input to 3dNetCorr. I'd like to use the GAM function to model the HRF in 3dDeconvolve, but am running into issues with different durations for each stimulus. In 3dDeconvolve, I'd ideally like to set-up my regressor with:

-stim_times_IM 1 "stims/subjID_all.timing.txt" GAM(8.6,.547,LIST_OF_STIM_DURATIONS) /
-stim_label 1 "all_stims"

I would like each stim in "...all.timing.txt" to use the GAM function, but each with a different duration parameter. Is this possible with the current version of 3dDeconvolve, and if not, is there a work-around to be able to generate an IM regressor like this but allowing different durations across stims?

Thanks so much for your help in-advance!
Taylor

Hi Taylor,

If Gang were in town, he would be cheering on this question. Fortunately, he is not. :)

No, 3dDeconvolve does not (yet) have this ability, to do duration modulation with any basis function but BLOCK. The IM aspect is a separate. We do plan to add this, but it might not happen anytime soon.

For now, the workaround has been to simply script the regressor generation yourself. That might be a little irritating, but as least it should work. For example, here is a little tcsh script that does it, generating regressors directly. Note that this is all based on post-steady state time and time points. Note also that my script was not doing IM, so it adds all of the regressors together (3dTstat -sum). You can take out that operation and just leave the individual files as they are. Oh, and this was using SPMG, which you can change to GAM.

set nt = 339
set tr = 0.68

set wdir = work.stim

if ( -d $wdir ) rm -fr $wdir
mkdir $wdir
cd $wdir

foreach type ( cor inc )
   foreach cond ( congruent incongruent )
   
      set infile = ../stim.$type.times.$cond.txt                  
                  
      set events = ( `cat $infile` )
                  
      foreach eind ( `count_afni -digits 1 1 $#events` )

         set ind3 = `ccalc -form "%03d" $eind`
         set event = $events[$eind]

         set onset = `echo $event | cut -d: -f 1`
         set dur   = `echo $event | cut -d: -f 2`

         3dDeconvolve -nodata $nt $tr -polort -1 -num_stimts 1 \
                      -stim_times 1 "1D: $onset" "SPMG1($dur)" \
                      -x1D x.$type.$cond.$ind3.1D -x1D_stop

      end

      1dcat x.$type.$cond.*.1D > all.$type.$cond.1D
      3dTstat -sum -prefix regr.$type.$cond.1D all.$type.$cond.1D

   end
end
cd ..

Does that seem reasonable?

-rick

Thanks so much for your response and help, Rick!

Just to clarify what you're doing in this script: read-in the events file, get the indexes, names, onsets, and durations of each stim and run 3dDeconvolve with each stimulus individually to generate a 1D regressor with the appropriate HRF function/duration. The 1dcat and 3dTstat are only used for concatenating these regressors together into a single file for a given type/cond combination.

In my specific IM context, should I create a 1D file (via the 3dDeconvolve call) for my "all_stims" file (combined names, onsets, and durations), generating a 1D file for every stimulus presented in the task, and then input each 1D file as it's own regressor in the "first-level" design matrix? If so, how should I handle the HRF option in the subsequent 3dDeconvolve calls? Once all stim 1D's have been created, this is what I envision:

3dDeconvolve -quiet \
                        -input {scanpath} \
                        -polort "A" \
                        -censor {censorpath} \
                        -ortvec {motionpath} 'motion_regressors' \
                        -num_stimts {N} \
                        -stim_times 1 "{outdir}/stim0.txt" \
                            GAM(8.6,.547) \ # <- what should go here?
                        -stim_label 1 "stim_1" \
                         ...
                        -stim_times N "{outdir}/stimN.txt" \
                            GAM(8.6,.547) \ # <- what should go here?
                        -stim_label N "stim_N" \
                        -x1D "{outdir}/concat_bseries_dmat.x1D" \
                        -x1D_stop -nobucket -jobs {numcores}

Will this output "{outdir}/concat_bseries_dmat.x1D" continue to work the same way with 3dLSS? Please let me know if I've overlooked or misunderstood anything. Thanks again in-advance for your help!

Trying to get back to some messages here...

Yes, with the 1dcat command, each regressor is separate, akin to using -stim_times_IM. But the main purpose is to then add them up (with 3dTstat), making what would be a normal regressor from the -stim_times option (well, _AM1 for duration modulation).

To apply this in a new 3dDeconvolve command, use -stim_file rather than -stim_times. If you are setting this up with afni_proc, that and any other regressor or timing file can be passed using -regress_stim_times, but then you can add -regress_stim_types to specify, for each one, whether it is 'times', 'file', 'AM2' or anything else. Let me know if you are doing that and have questions.

-rick