SPM Sensor-level stats demo
In this demo we will perform statistical analysis of sensor-level scalp x time images within subject. All classical statistical analyses in SPM are performed on either volumetric images in NIfTI format (can appear either as single files with .nii extension or pairs of files with .hdr and .img extensions) or data on meshes in GIfTI format (pairs of files with .gii and .dat extensions). Thus, any features derived from M/EEG must be converted into one of these formats first.
Then we will use the batch interface to specify a statistical model. There are many options in the batch tool, but they all eventually come down to specification of the GLM design matrix and covariance structure of the residuals. Therefore, any classical statistical analysis in SPM (time-frequency data, source images, group analysis etc.) will only differ from what you are about to do by the inputs you provide and the exact statistical design specification. You can see an example of group analysis of time-frequency data in the SPM12 manual chapter on Multimodal, Multisubject data fusion.
Export to images
To create 3D scalp-time images for each trial, the 2D representation of the scalp is created by projecting the sensor locations onto a plane, and then interpolating linearly between them onto a 32x32 pixel grid. This grid is then tiled across each timepoint.
-
Run MATLAB, make sure the root SPM folder is in your MATLAB path and write âspm eegâ in the command line.
-
Press the âBatchâ button and select the âSPM â M/EEG â Images â Convert2Imagesâ option in the batch editor.
-
For the input file, select the âPapMcbdspmeeg_run_01_sss.matâ file that contains every trial (i.e, before averaging), but with bad trials marked (owing to excessive EOG signals; see the manual chapter for more details).
-
Next select Mode, and select âscalp x timeâ.
-
Then, select âConditionsâ, select âSpecifyâ and enter the condition label âFamousâ. Then repeat for the condition labels âUnfamiliarâ and âScrambledâ.
-
To select the channels that will create your image, highlight the âChannel selectionâ, select âDelete: All(1)â and then select âNew: Select channels by typeâ and select âMEGMAGâ.
-
The final step in this tool is to name the Directory prefix âmagimgâ this can be done by highlighting âdirectory prefixâ, selecting âSpecifyâ, and the prefix can then be entered.
Random Field Theory, used to correct the statistics below, assumes a certain minimum smoothness of the data (at least three times the voxel size). We will add an additional step of Gaussian smoothing of the images to ensure this smoothness criterion is met.
-
Select âSPM-Spatial-Smoothâ from the batch tool menu. A âSmoothâ module will be added below âConvert2imagesâ module.
-
Click on this module, highlight âImages to smoothâ and press the âDependencyâ button in the bottom right corner of the batch window. In the list that comes up select âConvert2Images:M/EEG exported imagesâ and press âOKâ. This specifies the exported images that have not yet been created as input to the smoothing step.
-
Highlight âImplicit maskingâ and select âYesâ. This makes sure that smoothing doesnât go beyond the original head boundaries.
-
If everything is specified correctly the ârunâ button in the toolbar of the batch tool should turn green. Press it to run the batch.
Reviewing images
Once you have run the batch, a new directory will be created called âmag_img_PapMcbdspmeeg_run_01_sssâ. Within that directory will be three unsmoothed 4D NIfTI files, one per condition and three smoothed versions of the same files whose name starts with âsâ prefix. It is very important to note that these 4D files contain multiple âframesâ (i.e. 3D scalp-time images), one per trial (i.e. 296 in the case of unfamiliar faces).
-
To view one of these, press âDisplay â Imagesâ in the SPM Menu window, and select, say, the âcondition_Unfamiliar.niiâ file. But note that by default you will only see the first scalp-time image in each file (because the default setting of âFramesâ within the Select Image window is â1â). To be able to select from all frames, change the âFramesâ value from 1 to âInfâ (infinite) when opening the file, and now you will see all 296 frames (trials) that contained Unfamiliar faces. If you select one of them you can scroll will the cross-hair to see the changes in topography over time.
-
You can use CheckReg button in the main SPM menu to display several images side by side and compare them. This is useful, for instance to compare the original and smoothed version of an image.
A useful trick is to use regular expressions to select only part of the available images in a folder. For instance writing ^condition_F.* in the âFilterâ box and pressing Enter will only leave images whose name starts with âcondition_Fâ i.e. in this case unsmoothed images from the âFamousâ condition. This trick will be useful when specifying the statistical model below.
Model Specification
Now we have one image per trial (per condition), we can enter these into a GLM using SPMâs statistical machinery (in the same was that we treat other data from other modalities such as PET or fMRI). If we ignore temporal autocorrelation across trials, we can assume that each trial is an independent observation, so our GLM corresponds to a one-way, non-repeated-measures ANOVA with 3 levels (conditions).
-
To create this model, open a new batch, select âFactorial design specificationâ under âStatsâ on the âSPMâ toolbar at the top of the batch editor window. The first thing is to specify the output directory where the SPM stats files will be saved. So first create such a directory within the subjectâs sub-directory, calling it for example âStatsâ. Then go back to the batch editor and select this directory.
-
Highlight âDesignâ and from the current item window, select âOne-way ANOVAâ. Highlight âCellâ, select âNew: Cellâ and repeat until there are three cells.
-
Select the option âScansâ beneath each âCellâ heading (identified by the presence of a â<-Xâ). Select âSpecifyâ, and in the file selector window, remember to change the âFramesâ value from 1 to âInfâ as previously to see all the trials. Select all of the smoothed image files for one condition. This can be done by writing ^scondition* F.* for the âFamousâ condition (and respectively ^scondition* U._ and ^scondition_ S._ for âUnfamiliarâ and âScrambledâ), pressing Enter and then right-clicking the file list and pressing âSelect Allâ in the pop-up menu that appears. It is vital that the files are selected in the order in which the conditions will later appear within the Contrast Manager module (i.e., Famous, Unfamiliar, Scrambled).
-
Next highlight âIndependenceâ and select âYesâ, but set the variance to âUnequalâ. Keep all the remaining defaults (see other SPM chapters for more information about these options). Finally, to make the GLM a bit more interesting, we will add 3 extra regressors that model the effect of time within each condition (e.g., to model practice or fatigue effects).
-
Press âNew: Covariateâ under the âCovariatesâ menu, and for the âNameâ, enter âOrderâ. For vector, enter â1:880â (880 is 295+296+289) and select âInteractionsâ âWith Factor 1â and âCenteringâ âFactor 1 meanâ. By doing so, we create three (mean-centered within each level) regressors that model linear effects of time within each trial type.
-
For didactic purposes let us also define a random covariate that should not generate significant effects. Press âNew: Covariateâ under the âCovariatesâ menu, for the âNameâ, enter âRandomâ and for the âVectorâ enter
randn(1, 880)
(mean-centered by default). Before defining this covariate, we would recommend you typerng('shuffle')
at the MATLAB prompt such that everyone will create a different covariate.
This now completes the GLM specification, but before running it, we will add one more module.
-
Add a module for âModel estimationâ from the Stats option on the SPM toolbar menu and define the file name as being dependent on the results of the factorial design specification output. For âwrite residualsâ, keep ânoâ. Select classical statistics.
-
Run the pipeline by pressing the green ârunâ button.
Setting up contrasts and reviewing results
The final step in the statistics pipeline is creating some planned comparisons of conditions by using the âContrast Managerâ. We will do this interactively using the GUI tool, but you can see in the manual chapter how this can also be done using batch. The first contrast will be a generic one that tests whether significant variance is captured by the 7 regressors (3 for the main effect of each condition, 3 for the effects of time within each condition and 1 for the random regressor). This corresponds to an F-contrast based on a 7x7 identity matrix.
-
Press the âResultsâ button in the main SPM window. In the file selector that comes up select the âSPM.matâ file in the âStatsâ directory. In the window that comes up check the âF-contrastâ radio button and press âDefine new contrastâ button. Name this contrast âAll Effectsâ. Then define the weights matrix by typing in âeye(7)â (which is MATLAB for a 7x7 identity matrix). We will use this contrast later to plot the parameter estimates for these 7 regressors. Press âOKâ More interestingly perhaps, we can also define a contrast that compares faces against scrambled faces (e.g., to test whether the N170 seen in the average over trials is reliable given the variability from trial to trial, and to also discover where else in space or time there might be reliable differences between faces and scrambled faces).
-
So make another F-contrast, name this one âFaces (Fam+ Unf)
<>
Scrambledâ, and type in the weights â0.5 0.5 -1 0 0 0 0â (which contrasts the main effect of faces vs scrambled faces, ignoring any time effects (though SPM will complete the final zeros if you omit)). Note that we use an F-test because we donât have strong interest in the polarity of the face-scrambled difference. But if we did want to look at just positive and negative differences, you could enter two T-contrasts instead, with opposite signs on their weights. -
To test for the differences between Familiar and Unfamiliar faces make an F-contrast named âFam
<>
Unfâ, and type in the weights â1 -1 0 0 0 0 0â. -
Just to see an example of a T-contrast, create a new T-contrast for the random regressor, by checking the ât-contrastsâ button, naming the contrast âRandom+â (as it will only test for positive correlation with the random values) and specifying the contrast vector as [0 0 0 0 0 0 1]. Press OK.
-
Switch back to F-contrasts, highlight the âFaces (Fam+Unf)
<>
Scrambledâ contrast and press âDoneâ. Within the âStats: Resultsâ bar window which will appear on the left hand side, select the following: Apply Masking: None, P value adjustment to control: FWE, keep the threshold at 0.05, extent threshold {voxels}: 0; Data Type: Scalp-Time. -
Move the cursor to the earliest local maximum âthe first local peak in the first cluster - this corresponds to x=+26mm, y=-84mms and t=160ms (i.e. right posterior scalp). If you then press âPlot â Contrast Estimates â All Effectsâ, you will get 7 bars. The first three reflect the three main conditions (the red bar is the standard error from the model fit). You can see that Famous and Unfamiliar faces produce a more positive amplitude at this space-time point than Scrambled faces (the âN170â. Note that the âNâ notation comes from EEG whereas in MEG the polarity can be different depending on the sensor). The next three bars show the parameter estimates for the modulation of the evoked response by time. These effects are much smaller relative to their error bars (i.e., less significant) as is the random regressor effect.
-
Now in the interactive SPM window go to âContrastsâ menu, select âChange Contrastâ and âF: Fam
<>
Unfâ. You will see that nothing comes out as significant at the FWE p<0.05 level. To try a different way of significance testing go to âContrasts-Significance level â Changeâ. Press ânoneâ and select 0.01 as uncorrected (a.k.a. cluster-forming) threshold. You will see several clusters of different sizes. Their significance can be assessed by looking at the third from the left column in the stats table. You can see that only the largest cluster has a p-value of less than 0.05. You can now only display that cluster by changing the significance level again and repeating the steps but this time choosing an extent threshold value somewhere between the significant and the largest insignificant cluster size (e.g., 1500). -
Now try to do the same for the random regressor contrast. Is there any way you can get âsignificantâ results with it?
There are many further options you can try. For example, within the bottom left window, there will be a section named âDisplayâ, in the second drop-down box, select âOverlay â Sectionsâ and from the browser, select the âmaskâ file in the analysis directory. You will then get a clearer image of suprathreshold voxels within the scalp-time-volume.