Occasionally, it’s nice to look under the bonnet and see what’s going on during any automated process that you take for granted. More often than not, I do this when the automaticity has broken down and I need to fix it (e.g. my computer won’t start), or if I need to modify the process in a certain way as to make its product more useful to me (e.g. installing a TV card to make my computer more ‘useful’ to me). This is especially true with tools such as SPM.
One of the greatest benefits associated with using SPM is that it’s all there, in one package, waiting to be unleashed on your data. You could conduct all of your analyses using SPM only, and you could never need to know how SPM makes the pretty pictures that indicate significant brain activations according to your specified model. That’s probably a bad idea. You, at least, need to know that SPM is conducting lots and lots of statistical tests – regressions – as discussed in the previous post. If you have a little understanding of regressions, you’re then aware that what isn’t fit into your regression model is called a ‘residual’ and there are a few interesting things you can do with residuals to establish the quality of the regression model you have fit to your data. Unfortunately with SPM, this model fitting happens largely under the bonnet, and you could conduct all of your analyses without ever seeing the word ‘residual’ mentioned anywhere in the SPM interface.
Why is this? I’m not entirely sure. During the process of ‘Estimation’, SPM writes an image containing all of your residuals to disk (in the same directory as the to-be-estimated SPM.mat file) in a series of image files as follows:
(xxxx corresponds to the number of scans that contribute to the model.)
SPM then deletes these images once estimation is complete, leaving you having to formulate a workaround if you want to recover the residuals for your model. One reason SPM deletes the residual image files is that they take up a lot of disk space – the residuals add nearly 400MB (in our 300 scan model) for each participant which is a real pain if you’re estimating lots of participants and lots of models.
If you’re particularly interested in exploring the residual images (for instance, you can extract the timecourse of residuals for the entire run from an ROI using Marsbar), you need to tweak SPM’s code. As usual, the SPM message-board provides information on how to do this.
You can read the original post here, or see the relevant text below:
… See spm_spm.m, searching for the text “Delete the residuals images”. Comment out the subsequent spm_unlink lines and you’ll have the residual images (ResI_xxxx.img) present in the analysis directory.Also note that if you have more than 64 images, you’ll also need to change spm_defaults.m, in particular the linedefaults.stats.maxres = 64;which is the maximum number of residual images written.
>> edit spm_spm
%-Delete the residuals images%==========================================================================for i = 1:nSres,spm_unlink([spm_str_manip(VResI(i).fname,’r’) ‘.img’]);spm_unlink([spm_str_manip(VResI(i).fname,’r’) ‘.hdr’]);spm_unlink([spm_str_manip(VResI(i).fname,’r’) ‘.mat’]);end
%-Delete the residuals images
%for i = 1:nSres,
% spm_unlink([spm_str_manip(VResI(i).fname,’r’) ‘.img’]);
% spm_unlink([spm_str_manip(VResI(i).fname,’r’) ‘.hdr’]);
% spm_unlink([spm_str_manip(VResI(i).fname,’r’) ‘.mat’]);
>> edit spm_defaults
4) Find the following line (line 35 in my version of SPM5):
defaults.stats.maxres = 64;
and change to:
defaults.stats.maxres = Inf;
5) Save both files and run your analysis.
Make sure that once you no longer need to see the residual images, you unmodify the code, otherwise you’ll run out of harddisk-space very very quickly!