Statistics in sensor space
A standardised way or running sensor-level statistics on your MEG data is implemented in SPM5:
http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSpm
But nothing prevents you from finding your own way...
The following two scripts will help you
- convert fiff-files to SPM images (if necessary)
- run group statistics on MEG data in signal space in SPM 5
1. Converting Fiff-files to SPM images
This script has not been tested extensively, but it is based on the scripts at http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSPM.
% Modified from http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSPM
% takes a list of Fiff-files (cell array "fifflist{}") and converts MEG data to SPM image files,
% which can then be subjected to 2nd-level statistics, for example
% "rootdir" can contain the directory path common to all files
% the script will produce subdirectories with img-files in the directories of the input fiff-files
% so far only tested on one data set
% OH, March 2009
if exist('fifflist')~=1, % you can specify a list of files here (e.g. on-line averages for all subjects in your study)
fifflist = {'/fullpath/file4subj1.fif', ...
'/fullpath/file4subj2.fif', ...
'/fullpath/file4subj3.fif'};
end;
nr_fiffs = length(fifflist);
if exist('rootdir')~=1, % if not root directory specified, leave empty
root_dir = '';
end;
% GET GOING...
clear S;
for ff = 1:nr_fiffs, % for all Fiff-files...
% CONVERT FROM FIFF TO SPM FORMAT...
S.Fchannels = fullfile(spm('dir'),'EEGtemplates','FIF306_setup.mat');
S.veogchan = [62]; % Channel 62 is (bipolar) VEOG, MAY NEED EDITING
S.heogchan = [61]; % Channel 61 is (bipolar) HEOG, MAY NEED EDITING
S.veog_unipolar = 0; % MAY NEED EDITING
S.heog_unipolar = 0; % MAY NEED EDITING
S.conds = 1; % conditions in fiff-file, MAY NEED EDITING
S.grms = 1; % so that the splitting outputs mags, grads and grad RMS (grms)
[fiffpath,fiffname,fiffext,fiffversn] = fileparts(fifflist{ff});
S.Fdata = fullfile(root_dir, fifflist{ff}); % Input Fiff-file before splitting
fileSPMout = fullfile(root_dir, fiffpath, [fiffname '_SPM.mat']); % Output SPM file (if not specified, will be 'myexp.mat')
S.Pout = fileSPMout; % output for conversion from Fiff to SPM format (before splitting)
D0 = spm_eeg_rdata_FIF(S); % convert fiff- to SPM-format
% SPLIT DATA INTO MAGS/GRADS/EEG...
S.D = fileSPMout; % structure for splitting
D1 = spm_eeg_splitFIF(S); % split SPM files
% WRITE TO IMAGE VOLUMES:
% Select options (see help for spm_eeg_convertmat2ana3D):
clear S
S.interpolate_bad = 0;
S.n = 32;
S.pixsize = 3;
% Select trial types:
S.trialtypes = [1];
img_outnames = '';
% Mags:
S.Fname = fullfile(root_dir, fiffpath, [fiffname '_SPM-mags.mat']);
tmpname = spm_eeg_convertmat2ana3D(S);
img_outnames(1,:) = fullfile(root_dir, fiffpath, [fiffname '_SPM-mags'], 'trialtype1', 'average.img');
% Grad magnitude:
S.Fname = fullfile(root_dir, fiffpath, [fiffname '_SPM-grds.mat']);
tmpname = spm_eeg_convertmat2ana3D(S);
img_outnames(2,:) = fullfile(root_dir, fiffpath, [fiffname '_SPM-grds'], 'trialtype1', 'average.img');
% GradRMS magnitude:
S.Fname = fullfile(root_dir, fiffpath, [fiffname '_SPM-grms.mat']);
tmpname = spm_eeg_convertmat2ana3D(S);
img_outnames(3,:) = fullfile(root_dir, fiffpath, [fiffname '_SPM-grms'], 'trialtype1', 'average.img');
% SMOOTH IMAGES
P = img_outnames;
SmoothKernel = [5 5 10]; % % Smoothness in x (mm), y (mm) and z (ms), MAY NEED EDITING
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
end; %..ff
2. Sensor-level group analysis in SPM 5
% based on http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSpm
% to be run in SPM 5 EEG
% runs group statistics on files in "imgfiles"
% output written into directory "outdir"
% OH, March 2009
addpath /imaging/local/meg_misc; % for meg_batch_anova
if exist('outdir')~=1, % if no output directory specified, use current working directory
outdir = pwd;
end;
if exist('rootdir')~=1, % if not root directory specified, leave empty
root_dir = '';
end;
% Here: One group of subjects, 2 conditions
% (you can also specify more groups of subjects, or test one condition against zero)
if exist('imgfiles')~=1,
cc = 1;
imgfiles{1}{cc} = ['/thispath/subj1_con1.img'; 'thispath/subj1_con2.img']; cc=cc+1;
imgfiles{1}{cc} = ['/thispath/subj2_con1.img'; 'thispath/subj2_con2.img']; cc=cc+1;
imgfiles{1}{cc} = ['/thispath/subj3_con1.img'; 'thispath/subj3_con2.img'];
end;
nr_subjects = cc;
% Attach root directory
clear Panova;
for i=1:nr_subjects, % create full image file names, including root directory etc.
[m,n] = size(imgfiles{1}{i});
for j=1:m,
Panova{1}{i}(j,:) = fullfile( root_dir, imgfiles{1}{i}(j,:) );
end; %..j
end; %..i
meg_batch_anova(Panova,imgset(ss).outdir); % Run SPM stats