Jamie Johnston johnston at KIN.UCALGARY.CA
Sun May 3 22:12:32 CEST 2009

Thanks for your response.
Let me clarify....I have 8 subjects (with 5 channels of data, 2 with 4
channels which I'm not using at this point)...I used only 2 subjects to
test the code (for faster debugging).   I do want to do a within subject
statistical test between my conditions (of which I have 3, but I am only
inputting 2 into freqstatistics as I was unclear whether I could run
comparisons across 3 conditions).
As you correctly point out, I did compute coherence across my 5 channels
first, resulting in 10 spectra...this is what I inputted into
freqstatistics, which is clearly incorrect.  This is what I thought,
however I didn't know exactly what the data input should look like.
So, just to clarify, I'm running
freqanalysis - inputting raw data, returning "powandcsd'
freqdescriptives - inputting data from freqanalysis, returning 'coh'
freqgrandaverage (keep individual 'yes') - inputting data from
freqdescriptives, returning a grandaverage
freqstatistics - inputting two grandaverages (for 2 conditions), using
the following parameters:
%Compute Permutation Test
cfg = [];
cfg.parameter = 'cohspctrm';
cfg.method = 'montecarlo';
cfg.frequency = [0 50];
cfg.statistic = 'indepsamplesT';
cfg.correctm = 'cluster';
cfg.clusteralpha = 0.05;
cfg.clusterstatistic = 'maxsum';
cfg.minnbchan = 2;
cfg.tail = 0;
cfg.clustertail = 0;
cfg.alpha = 0.05;
cfg.numrandomization = 100;
cfg.computestat = 'yes';
subj = length(Subjects);
for i = 1:subj
  design(1,i) = i;
for i = 1:subj
  design(1,subj+i) = i;
design(2,1:subj)        = 1;
design(2,subj+1:2*subj) = 2;   = design;
cfg.uvar  = 1;
cfg.ivar  = 2;
[stat] = freqstatistics(cfg, grandavg{1}, grandavg{2});
Are you saying, I should use the output from freqanalysis (skipping
freqdescriptives) as input to freqgrandaverage?  Also, should my
"cfg.parameter" for the freqstatistics function still be 'cohspctrm' or
Thanks again,
From: FieldTrip discussion list [mailto:FIELDTRIP at NIC.SURFNET.NL] On
Behalf Of jan-mathijs schoffelen
Sent: May 3, 2009 1:34 PM
Subject: Re: [FIELDTRIP] independsamplesZcoh
Dear Jamie,
For me it is not exactly clear what you want to do. In an earlier
message you referred to our paper using a permutation test to test for a
significant difference in coherence between conditions (Maris et al
2007). Essentially, as described, this is a test which is performed
within each subject allowing you to do statistical inference about the
potential difference between two conditions. As such this is the type of
test indepsamplesZcoh can perform, if properly used (see below). Yet,
you describe using two subjects as an input. This to me sounds rather
that you would like to do statistics across subjects (although 2
subjects of course is a rather low number). This is NOT something
indepsamplesZcoh can do  for you. In general it is possible to test for
a significant difference between two conditions across a population of
subjects, but this would require a different approach. Rather than
shuffling single observations across conditions PRIOR TO COMPUTING THE
COHERENCE DIFFERENCE (sorry about the capitals but this is essential for
what is to follow below), one would swap the sign of the Z-transformed
coherence difference for a random subset of subjects prior to averaging.
It seems as if you computed coherence spectra between all unique pairs
of channels (4x5)/2 and used this as an input to freqstatistics. Yet,
for single subject statistics this does not make sense, because
indepsamplesZcoh expects fourier-spectra in the input. Within the
function Z-transformed coherence difference will be computed between all
pairs of input channels (in your case this would be (9x10)/2 (even
though the function does not know you provide it with the wrong input),
and multiplying this number with 52 would give your 'magical' 2340).
So, indeed you should either format your data in a different way using
single subject fourier spectra in two conditions as an input to
freqstatistics, or using a different statistical test to test for
differences across subjects.
On May 3, 2009, at 7:00 PM, Jamie Johnston wrote:

Hi all -
I am trying to run a monte carlo - indepsamplesZcoh - cluster on my data
using freqstatistics.  I input two data files into freqstatistics with
the cohspctrm having dimensions 2 (subjects) x 10 (channels, # of
coherence spectra) x 52 (frequencies).  I run into a dimension mismatch
in the function clusterstat.  If I run any other statistic (i.e.,
indepsamplesT) it runs fine.  When running the indepsamplesT,
clusterstat receives two inputs: statobs (520x1) and statrnd (520x100).
These dimensions make sense to me.  However, when running
indepsamplesZcohthese two variables have dimensions 2340x1 and 2340x100,
respectively.  This happens around lines 104-108 in indepsamplesZcoh.m
with computation of the variables "chancmbsel" and "nnewsamples."  I'm
not understanding what these variables do, but my guess is that I need
to setup my data files differently in the beginning.  My understanding
of what this analysis protocol does is compute the z-statistic on each
channel of coherence data (10 for each data file) and then find the
difference between the z-statistic for each channel across the data
files. Once this is complete it runs the permutations to determine the
Please verify that what I have done is correct and any help with the
error I am getting would be greatly appreciated.
Jamie Johnston, Ph.D.
Assistant Professor
Faculty of Kinesiology
University of Calgary
2500 University Dr. NW
Calgary, AB
T2N 1N4
Phone: +1 (403) 220-3649
Fax: +1 (403) 284-3553
email: johnston at
The aim of this list is to facilitate the discussion between users of
the FieldTrip toolbox, to share experiences and to discuss new ideas for
MEG and EEG analysis.
The aim of this list is to facilitate the discussion between users of
the FieldTrip toolbox, to share experiences and to discuss new ideas for
MEG and EEG analysis.

The aim of this list is to facilitate the discussion between users of the FieldTrip  toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis. See also and
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the fieldtrip mailing list