Tool for generating polynomial detrending regressors

Is there a tool that can generate polynomial detrending regressors? I know 3dTProject and nilearn have some built-in options (-polort, signal.clean), but I was looking for a way to get those regressors into a text file for example.

Hello,

AFNI’s 3dDeconvolve command is used for generation of regression matrices, including when no data is in hand. To generate Legendre polynomials of degree 3, using 200 time points and TR=2s, consider something like:

3dDeconvolve -nodata 200 2 -polort 3 -x1D x1-3.xmat.1D

To generate regressors that span multiple (4) runs (one could zero pad, but), up the number of time points, and add -concat:

3dDeconvolve -nodata 800 2 -polort 3 \
    -concat '1D: 0 200 400 600'      \
    -x1D x4-3.xmat.1D

If an -input option includes time series data, but you just want a regression matrix, use -x1D_stop to prevent it from doing the actual fitting.

  • rick

Thank you Rick, that’s very useful information. It shouldn’t really matter if I use the -nodata flag or the actual -input time_series.txt as long as the number of time points, TR, polort is consistent, is that right?

Also I noticed 3dDeconvolve creates a column of 1s, do I need to include it as well in my regression matrix?

And what polort degree do you recommend using for functional data?

Sure, using -input or -input1D will allow you to pass multiple datasets as multiple runs, if that matters (instead of needing -concat).

Yes, modeling the constant baseline term is quite important, unless the input data is already zero mean. It should not be harmful in any case, especially if you have other regressors besides the polynomials. And even if the mean is already zero, it may be preferable to appropriately count that lost degree of freedom.

Our (Bob’s) rule of thumb for polort is 1 + floor(run_time/150s). That is to say:

   1 if run < 150s
   2 if 150 s <= run_time < 300 s
   3 if 300 s <= run_time < 450 s
   etc.
  • rick
1 Like