
function [stat] = freqstatistics(cfg, varargin)

%%%%USAGE%%%%% Stat = freqstatistics(cfg, subj1cond1, subj1cond2, subj2cond1, subj2cond2 ); %take care that this corresponds with how you specified your design.

%%%%USAGE%%%%% Stat = freqstatistics(cfg, 349_XM, 349_Vis, 449_XM, 449_Vis, 732_XM, 732_Vis, 868_XM, 868_Vis, 1257_XM, 1257_Vis, 1299_XM, 1299_Vis); %take care that this corresponds with how you specified your design.

% FREQSTATISTICS computes the probability for a given null-hypothesis using
% a parametric statistical test or using a non-parametric randomization test.
%
% Use as
%   [stat] = freqstatistics(cfg, freq1, freq2, ...)
% where the input data is the result from FREQANALYSIS, FREQDESCRIPTIVES
% or from FREQGRANDAVERAGE.
%
% The configuration can contain the following options for data selection
%   cfg.channel     = Nx1 cell-array with selection of channels (default = 'all')
%                     see CHANNELSELECTION for details
%   cfg.latency     = [begin end] in seconds or 'all' (default = 'all')
%   cfg.frequency   = [begin end], can be 'all' (default)
%   cfg.avgoverchan = 'yes' or 'no' (default)
%   cfg.avgovertime = 'yes' or 'no' (default)
%   cfg.avgoverfreq = 'yes' or 'no' (default)
%
% Furthermore, the configuration should contain
%   cfg.method       = different methods for calculating the probability of the null-hypothesis,
%                    'montecarlo' use a non-parametric randomization test to get a Monte-Carlo estimate of the probability,
%                    'analytic'   use a parametric test that results in analytic probability,
%                    'stats'      use a parametric test from the Matlab statistics toolbox,
%                    'glm'        use a general linear model approach.
%
% The other cfg options depend on the method that you select. You
% should read the help of the respective subfunction STATISTIC_XXX
% for the corresponding configuration options and for a detailed
% explanation of each method.
%
% See also FREQANALYSIS, FREQDESCRIPTIVES, FREQGRANDAVERAGE

% This function depends on STATISTICS_WRAPPER
%
% TODO change cfg.frequency in all functions to cfg.foi or cfg.foilim

% Copyright (C) 2005-2006, Robert Oostenveld
%
% $Log: freqstatistics.m,v $
% Revision 1.8  2006/07/12 09:18:17  roboos
% improved documentation
%
% Revision 1.7  2006/06/20 16:25:58  ingnie
% updated documentation
%
% Revision 1.6  2006/06/20 12:57:26  roboos
% updated documentation
%
% Revision 1.5  2006/06/13 14:48:09  ingnie
% updated documentation

load('allsubjects.mat')
cfg = [];

cfg.method = 'montecarlo';

cfg.statistic = 'diff';

cfg.parameter = 'cohspctrm'; %This is at least what I expect your data objects to contain!

cfg.numrandomization = 500; %a number

% cfg.design = [1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14; 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2]; %this specifies how the data has to be interpreted

cfg.design = [1 1 2 2 3 3 4 4 5 5 6 6; 1 2 1 2 1 2 1 2 1 2 1 2]; %this specifies how the data has to be interpreted

cfg.ivar = 2; %row-index of independent variable, which is the conditcfg=ion in your case

cfg.uvar = 1; %row-index of the �unit�-variable, your unit of observation, which are your individual subjects.

   %the design-matrix will be shuffled, by swapping the 1 and 2s in the ivar-row, while keeping the uvar-doublets together.

cfg.correctm = 'yes'; %keep it at this for the time being, we have to develop a cunning strategy to incorporate something about the neighbourhood structure of your ROIs

  %as soon as you get your script running, you can try to incorporate fancy multiple-comparison correction strategies, such as clustering in time and frequency.


for j = 1:length(data1257Vis.label);
  cfg.neighbours{j}.label = data1257Vis.label{j};
  cgf.neighbours{j}.neighblabel = {};
end
 



% call the general function

[stat]=statistics_wrapper(cfg, varargin{:});

