Can you use AFNI's 3dFWHMx with SPM's residual data?

The following was a conversation on the message boards of my old blog, and I thought it might be interesting to those of you using AFNI tools on SPM data. As I mention below, I'm not sure whether the following approach works, but it seemed reasonable. If anyone else has any thoughts, I'd like to hear them in the comments section below!

[EDIT 03.26.2019]: Using ResMS.nii is probably NOT appropriate for estimating the smoothness of the data; instead, see the comment below by Jasmine Hect, who recommends saving out the residuals during the “Estimate” stage of the analysis. When you press the Estimate button in SPM there is an option for writing out the Residuals, which by default is set to No. Change this to Yes, concatenate the timeseries using a command like fslmerge or 3dTcat, and then run 3dFWHMx on that dataset.

My previous comments were based more liberal cluster-defining thresholds such as p=0.05, which seemed to give comparable cluster size estimates when using either SPM’s ResMS.nii or AFNI’s errts+tlrc. At lower thresholds such as p=0.001, the cluster sizes appear to differ dramatically. I would therefore recommend either running your model estimation in AFNI and using the errts+tlrc file for smoothness estimation, or using the residuals output by SPM.

Hi Andy, 
I've done all my analyses in SPM8, but I'd like to use 3dClustSim for cluster level correction. I'm wondering if instead of using AFNI's 3dFWHM to get estimates of the smoothness, can I use the effective smoothness values listed at the bottom of the results file from my SPM.mat?

The SPM smoothness estimates Val is referring to

The SPM smoothness estimates Val is referring to

Or are those the "traditional" smoothness values you mention and I've missed the point of doing the -acf? If you recommend using 3dFWHM function, can you tell me what these inputs refer to if I have files generated via SPM? 3dFWHMx -mask mask+tlrc.HEAD -acf tmp.txt errts+tlrc.HEAD

Thank you so much for your helpful blog and videos!


Hi Val,

Yes, you should be able to use 3dFWHMx on the residuals of the SPM data. I wouldn't use the estimated FWHMx values you see at the bottom of the SPM results window, as they probably underestimate the true smoothness of the data.

If you want to use AFNI's 3dFWHMx, here's what the options refer to (and what they correspond to in the SPM dataset, surrounded by brackets):

-mask [mask.nii]: Refers to a mask covering the whole brain and excluding non-brain material (e.g., air)

-acf tmp.txt: Computes the autocorrelation function that fits an updated model of the smoothness (you can actually omit the tmp.txt part, I'm not sure what the output in the tmp.txt file means)

errts+tlrc.HEAD [ResMS.nii]: Refers to the residual time series (although in SPM, this is a single volume, not a time series; and it is the mean square of the residuals, not the residuals themselves)

Note that there's another option in 3dFWHMx called 2difMAD, which is used for single-volume residual datasets (such as PET images). It might be applicable in this case since the ResMS.nii image is a single volume, but in my experience the difference is negligible between including the 2difMAD option and omitting it, at least for fMRI data.

Here's what I would recommend:

1. Calculate the square root of the ResMS.nii image to "undo" the mean square scaling of the residuals: 3dcalc -a ResMS.nii -expr 'sqrt(a)' -prefix MS.nii

2. Use this MS.nii dataset to estimate your FWHMx: 3dFWHMx -acf -mask mask.nii MS.nii

3. Use the second row of the ACF output with 3dClustSim to estimate your updated clusters.

Again, I'm not 100% sure about this entire procedure - for example, taking the square root of the ResMS.nii dataset. But in my simulations it provided smoothness estimates that were comparable to what I had seen when analyzing AFNI data with similar smoothing kernels.

Good luck!