How to identify subjects with unacceptable motion via SPM outputs

After realignment processing in SPM, we obtain a file named rp_*.txt containing a matrix with six columns.
How can we determine if a subject’s head motion is unacceptable using this matrix?
What criteria should I apply?

Thank you for your help.

Hi @Olivia,

You might find this script helpful in calculating FD from the motion parameters: CPAC.generate_motion_statistics.generate_motion_statistics - C-PAC 1.8.6 Beta documentation

In regards to thresholding/excluding, that is partly subjective based on how much data you collect per subject, how many subjects you can afford to lose, and the base expectations of the subject quality (e.g. be more lenient with kids).


Thank you very much!

Same but if you have to stay in matlab / octave world:

SPMup has some function to help do more of less the same thing as the python script above.

I refactored some of this code into a different toolbox (adding the src/QA folder to the path should be enough):

1 Like

Couple of things: you may want to consider “censoring” the timepoints with too much motion rather than discarding the whole run or the whole subject. Especially if your data is quite “precious”.

The matlab functions above try to identify outliers timepoints a bit like fmriprep gives you outliers regressors in its output.

But as @Steven said above what threshold to use to exclude timepoints, runs, subjects very much depends on your study.

Hi @Remi-Gau
Thank you!
This is exactly what I want.
Living too long in matlab world, I can’t get rid of it anymore.

1 Like

don’t hesitate to report here or on the respective repos if you have issues

Hi @Remi-Gau ,
Thank you!

I tried utilizing the following function:

[new_files, FD, glo] = spmup_realign_qa(P, 'Average', ['sub01/session_01']);

However, I encountered errors during execution. Specifically, the function stopped at Line 155 with the following error message:

Error using strcmp
Not enough input arguments.

Upon further investigation, I discovered that the variables fparts and mparts are both empty. These variables are generated by the following lines of code:
Line 146 :

fidx = find(~cellfun(@isempty, regexp(fparts, '^(task)', 'once'), 'UniformOutput', true));

Line 153:

midx = find(~cellfun(@isempty, regexp(mparts, '^(task)', 'once'), 'UniformOutput', true));

Due to this issue, the function is unable to proceed. Could you kindly provide guidance on how to address this issue?

are your files named following BIDS conventions?

spmup is kind of BIDS centric to a certain extend so if your data does not comply with BIDS you may have problems like this

not 100% sure but the code in BIDSPM may be more robust as it’s not trying to guess where the txt file but you have to tell it where it is

The file names of the NIfTI files are generated by SPM and are structured like this example: reg_f2023-12-03_15-59-190844-00005-00005-1.nii.

Are these file names compliant with the BIDS conventions? If not, are there methods available to transform them?

During debugging, I discovered that this function correctly locates the text files, specifically those starting with “rp*.txt”.


let me try if I can reproduce your error

OK I get the same error with spmup but everything is fine if you use the bidspm functions:

boldFile = fullfile(pwd, 'reg_f2023-12-03_15-59-190844-00005-00005-1.nii');
motionFile = fullfile(pwd, 'rpreg_f2023-12-03_15-59-190844-00005-00005-1.txt');
[confounds, figures] = realignQA(boldFile, motionFile);

Thank you very much!

There is no help content in the function “realignQA.” So I opted to use “spmup_realign_qa”.

For this function:
[confounds, figures] = realignQA(boldFile, motionFile)

Does “boldFile” refer to the mean file outputted by the realignment operation in SPM, or does it refer to the NIfTI file corresponding to the time point I want to examine?

And “motionFile” refers to the file containing motion parameters, correct?