Diff for "SensorSpm" - Meg Wiki
location: Diff for "SensorSpm"
Differences between revisions 7 and 16 (spanning 9 versions)
Revision 7 as of 2008-11-12 18:03:19
Size: 2431
Editor: JasonTaylor
Comment:
Revision 16 as of 2009-01-22 13:24:16
Size: 4052
Editor: RikHenson
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
=== Creating and Viewing 3D Sensor SPMs ===
3D topography x time sensor SPMs can help you identify the latency and location of effects in sensor space.
== 3D Sensor SPMs ==
3D topography x time sensor SPMs can help you identify the latency and location of effects in sensor space. For example, here's a word-pseudoword effect (N=19) on magnetometers and gradiometers (RMS), thresholded for height (p<.001 unc) and extent (p<.05 corr):
Line 6: Line 6:
Figure: A word-pseudoword effect (N=19) on magnetometers and gradiometer magnitude.

1. Select an averaged file (m*.mat), split it into separate files for magnetometers, gradiometers, and gradiometer-magnitude (m*-mags.mat, m*-grds.mat, and m*-grms.mat, respectively).
=== Creating 3D Sensor SPMs ===
1. Select an averaged file (m*.mat), split it into separate files for magnetometers, gradiometers, and gradiometer-magnitude (m*-mags.mat, m*-grds.mat, and m*-grms.mat, respectively). (Note you can do a similar analysis within a single subject by writing epochs to images).
Line 29: Line 28:
spm_eeg_convertmat2ana3D(S); spm_eeg_convertmat2ana3D(S);}}}
3. Smooth image volumes (optional, but good idea for grms, since distribution of RMS of gradiometer values [over voxels] is not Gaussian, even if by Central Limit Theorem, the distribution of the mean over enough subjects will be).

{{{
% Select files (or pass from stage above)
P = spm_select(Inf,'image','Select image file(s)',[],pwd,'.*img');
% Smoothness in x (mm), y (mm) and z (ms)
SmoothKernel = [5 5 10];
for n=1:size(P,1);
           [pth,nam,ext] = fileparts(P(n,:));
    Pout{n} = fullfile(pth,['s' nam ext]);
           spm_smooth(spm_vol(P(n,:)),Pout{n},SmoothKernel);
    Pin = strvcat(P(n,:),Pout{n});
    spm_imcalc_ui(Pin,Pout{n},'((i1+eps).*i2)./(i1+eps)',{[],[],'float32',0});
end
%The final imcalc step above is just to reinsert NaN's for voxels outside space-time volume into which data were smoothed
Line 31: Line 45:
3. Then compute an ANOVA over subjects (use GUI to batch, or a script if you have one).
Line 33: Line 46:
4. To view the results, navigate to the directory that contains the SPM.mat for your ANOVA. In an SPM window, click 'Results', Select SPM.mat, Unwhitened EOI, don't mask, whatever title, choose your p-value and extent thresholds (I usually start with .001 and 0). Click 'whole brain' to view whole-volume results. The coordinates on the far right show x (mm), y (mm), and time (ms). 4. Then compute an ANOVA over subjects. Either use SPM's GUI, or a script like 'meg_batch_anova.m' which can be found in /imaging/local/meg_misc (or here http://imaging.mrc-cbu.cam.ac.uk/svn/meg_misc/devel/), eg:
Line 35: Line 48:
Ignore the glass brain images. To view the cloud-in-a-box images, click 'overlays'->'sections', and select mask.img. Lovely. If you want to write out the image volume, click 'save' and give it a name. You can then view it using 'Display' or 'Check Reg'. {{{
% wd is your working directory (eg pwd)
outdir = fullfile(wd,'SensorTimeSPMs');
meg_batch_anova(Pout,outdir);
}}}
Line 37: Line 54:
If you want to correct for extent, rather than 'Results', click 'Toolbox'->'ns'. Select SPM.mat, Unwhitened EOI, don't mask, whatever title, no p-value adjustment, threshold {p} .001 (or your choice), extent threshold 0. The leftmost column ('cluster-level p-corrected') shows p-values corrected for cluster extent. Note that this information was absent when you clicked 'Results'. === Viewing 3D Sensor SPMs ===
To view the results, navigate to the directory that contains the SPM.mat for your ANOVA. In an SPM window, click 'Results' (1), select SPM.mat (2), select contrast Unwhitened EOI (3), and select options: (4) don't mask, whatever title, choose your p-value and extent thresholds (I usually start with .001 and 0).
Line 39: Line 57:
If you want to view or write out an image thresholded for cluster extent, determine what cluster size ('cluster-level k-voxel') needed to achieve your desired p-value ('cluster-level p-corrected'; e.g., 0.05). Then follow the above 'Toolbox'->'ns' directions, but this time enter the k-voxel extent threshold when prompted (e.g., 200). Now the results are thresholded for both height and extent. View and save as above. attachment:Demo3dSpm1Scaled.jpg

Click 'whole brain' (5) to view whole-volume results. The coordinates on the far right (6) show x (mm), y (mm), and time (ms). Ignore the glass brain images (7).

attachment:Demo3dSpm2Scaled.jpg

To view the cloud-in-a-box images, click 'overlays'->'sections', (8) and select mask.img (9). Lovely (10). If you want to write out the image volume, click 'save' and give it a name. You can then view it using 'Display' or 'Check Reg'.

attachment:Demo3dSpm3Scaled.jpg

If you want to correct for extent, rather than clicking 'Results', click 'Toolbox'->'ns'. As above, select SPM.mat, Unwhitened EOI, options: don't mask, whatever title, no p-value adjustment, threshold {p} .001 (or your choice), extent threshold 0. The leftmost column ('cluster-level p-corrected') shows p-values corrected for cluster extent (11). Note that this information was absent when you clicked 'Results'.

attachment:Demo3dSpm4Scaled.jpg

If you want to view or write out an image thresholded for cluster extent, determine what cluster size ('cluster-level k-voxel') needed to achieve your desired p-value ('cluster-level p-corrected'; in the example, 214 gets p=0.052 (12)). Then follow the above 'Toolbox'->'ns' directions, but this time enter the k-voxel extent threshold when prompted (eg., 215 (13)). Now the results are thresholded for both height and extent (14). View and save as above.

attachment:Demo3dSpm5Scaled.jpg

3D Sensor SPMs

3D topography x time sensor SPMs can help you identify the latency and location of effects in sensor space. For example, here's a word-pseudoword effect (N=19) on magnetometers and gradiometers (RMS), thresholded for height (p<.001 unc) and extent (p<.05 corr):

attachment:WdNw3DSensorSpm.jpg

Creating 3D Sensor SPMs

1. Select an averaged file (m*.mat), split it into separate files for magnetometers, gradiometers, and gradiometer-magnitude (m*-mags.mat, m*-grds.mat, and m*-grms.mat, respectively). (Note you can do a similar analysis within a single subject by writing epochs to images).

clear S
S.D='mae_mydata.mat';
spm_eeg_splitFIF_grms(S);

2. Write image volumes.

% Select options (see help for spm_eeg_convertmat2ana3D):
clear S
S.interpolate_bad = 0;
S.n = 32;
S.pizsize = 3;
% Select trial types:
S.trialtypes = [1 2];
% Mags:
S.Fname = 'mae_mydata-mags.mat';
spm_eeg_convertmat2ana3D(S);
% Grad magnitude:
S.Fname = 'mae_mydata-grms.mat';
spm_eeg_convertmat2ana3D(S);

3. Smooth image volumes (optional, but good idea for grms, since distribution of RMS of gradiometer values [over voxels] is not Gaussian, even if by Central Limit Theorem, the distribution of the mean over enough subjects will be).

% Select files (or pass from stage above)
P = spm_select(Inf,'image','Select image file(s)',[],pwd,'.*img');
% Smoothness in x (mm), y (mm) and z (ms)
SmoothKernel = [5 5 10];  
for n=1:size(P,1);
           [pth,nam,ext] = fileparts(P(n,:));
           Pout{n}       = fullfile(pth,['s' nam ext]);
           spm_smooth(spm_vol(P(n,:)),Pout{n},SmoothKernel);
           Pin = strvcat(P(n,:),Pout{n});
           spm_imcalc_ui(Pin,Pout{n},'((i1+eps).*i2)./(i1+eps)',{[],[],'float32',0}); 
end
%The final imcalc step above is just to reinsert NaN's for voxels outside space-time volume into which data were smoothed

4. Then compute an ANOVA over subjects. Either use SPM's GUI, or a script like 'meg_batch_anova.m' which can be found in /imaging/local/meg_misc (or here http://imaging.mrc-cbu.cam.ac.uk/svn/meg_misc/devel/), eg:

% wd is your working directory (eg pwd)
outdir = fullfile(wd,'SensorTimeSPMs');
meg_batch_anova(Pout,outdir);

Viewing 3D Sensor SPMs

To view the results, navigate to the directory that contains the SPM.mat for your ANOVA. In an SPM window, click 'Results' (1), select SPM.mat (2), select contrast Unwhitened EOI (3), and select options: (4) don't mask, whatever title, choose your p-value and extent thresholds (I usually start with .001 and 0).

attachment:Demo3dSpm1Scaled.jpg

Click 'whole brain' (5) to view whole-volume results. The coordinates on the far right (6) show x (mm), y (mm), and time (ms). Ignore the glass brain images (7).

attachment:Demo3dSpm2Scaled.jpg

To view the cloud-in-a-box images, click 'overlays'->'sections', (8) and select mask.img (9). Lovely (10). If you want to write out the image volume, click 'save' and give it a name. You can then view it using 'Display' or 'Check Reg'.

attachment:Demo3dSpm3Scaled.jpg

If you want to correct for extent, rather than clicking 'Results', click 'Toolbox'->'ns'. As above, select SPM.mat, Unwhitened EOI, options: don't mask, whatever title, no p-value adjustment, threshold {p} .001 (or your choice), extent threshold 0. The leftmost column ('cluster-level p-corrected') shows p-values corrected for cluster extent (11). Note that this information was absent when you clicked 'Results'.

attachment:Demo3dSpm4Scaled.jpg

If you want to view or write out an image thresholded for cluster extent, determine what cluster size ('cluster-level k-voxel') needed to achieve your desired p-value ('cluster-level p-corrected'; in the example, 214 gets p=0.052 (12)). Then follow the above 'Toolbox'->'ns' directions, but this time enter the k-voxel extent threshold when prompted (eg., 215 (13)). Now the results are thresholded for both height and extent (14). View and save as above.

attachment:Demo3dSpm5Scaled.jpg

CbuMeg: SensorSpm (last edited 2013-03-08 10:02:45 by localhost)