Thursday, June 19, 2014

Updated SPM Command Line, Including Beta Series Option

I've updated the code of the previously discussed previous script in the previous post, previously, including the addition of more help text to explain certain options and termination of the script if the timing file is not found.

However, the biggest change is a block of code to convert the timings files so that each trial is now a regressor, before entering them into the GLM. With so many regressors, the GLM will look a little funky; possibly something like this:

Note that, since there are so many regressors and so many scans, not all of them are going to be labeled individually; but it should look as though there is only one estimation per column, or blip of white underneath each regressor. Also due to space constraints the parameter estimability may not be completely visible, but when each trial is being estimated individually, you should still get a beta for each trial. Check the output directory to make sure that you have the number of betas you think you should have: one for each trial, plus the amount of session constants (usually equal to the number of runs for the subject).

The updated script can be found here; as always, send me any comments if you encounter any serious issues or bugs. I recommend using it as a replacement for the previously discussed previous script, since it can either estimate each trial individually or average them together, depending on whether you set the DO_BETASERIES flag to 1 or 0.

All of this is explained clearly in the following video:


  1. Thank you so much for sharing your valuable knowledge and especially your script with us
    I first tried to run the script (Running SPM First-Level Analysis from the Command Line)
    and second
    Updated SPM Command Line, Including Beta Series Option
    but it still gives me the same error ie the following error

    Running job #1
    Running 'fMRI model specification'

    SPM8: spm_fMRI_design (v4185) 13:03:46 - 31/10/2014
    Saving fMRI design : ...SPM.mat saved

    SPM8: spm_fmri_spm_ui (v4421) 13:03:46 - 31/10/2014
    Failed 'fMRI model specification'
    Cell contents reference from a non-cell array object.
    In file "C:\Program Files\spm8\spm_Ce.m" (v3527), function "spm_Ce" at line 53.
    In file "C:\Program Files\spm8\spm_fmri_spm_ui.m" (v4421), function "spm_fmri_spm_ui" at line 345.
    In file "C:\Program Files\spm8\config\spm_run_fmri_spec.m" (v4185), function "spm_run_fmri_spec" at line 301.

    The following modules did not run:
    Failed: fMRI model specification

    ??? Error using ==> cfg_util at 835
    Job execution failed. The full log of this run can be found in MATLAB command window, starting
    with the lines (look for the line showing the exact #job as displayed in this error message)
    Running job #1

    Error in ==> spm_jobman at 217

    Error in ==> Updated_SPM_Command_Line at 238

  2. Thank you for sharing this code! I just ran it with DO_BETASERIES, and have a question about the output. I have three conditions in my study. I see that all of my betas were estimated and saved, but I'm not sure how to know which one corresponds to each condition. Are they simply organized sequentially?

    1. Hi there,

      Yes, they are organized sequentially; you can see this by loading up the SPM.mat file and typing SPM.Vbeta. You should see the name of each condition followed by a number, which corresponds to the occurrence of that condition.

      Read more here (and watch video #1 at the end):